MCPcopy Index your code
hub / github.com/ChinaGodMan/UserScripts / fetch_script_json

Function fetch_script_json

utils/script_user_info_generator.py:27–49  ·  view source on GitHub ↗
(greasyfork_id, is_sleazy=False, retrie=True)

Source from the content-addressed store, hash-verified

25
26
27def fetch_script_json(greasyfork_id, is_sleazy=False, retrie=True):
28 base_url = 'https://api.sleazyfork.org' if is_sleazy else 'https://api.greasyfork.org'
29 base_site_url = base_url.replace('api.', '')
30 url = f'{base_url}/scripts/{greasyfork_id}.json'
31 try:
32 response = requests.get(url)
33 if response.status_code == 404 and retrie:
34 return fetch_script_json(greasyfork_id, not is_sleazy, False)
35 response.raise_for_status()
36 data = response.json()
37 script_name = data.get("name", "NULL")
38 users = data.get("users", [])
39 user_links = [
40 f"[🧑‍💻 **@{user.get('name')}**]({base_site_url}/users/{user.get('id')})"
41 for user in users
42 ]
43 script_link = f"[{script_name}]({base_site_url}/scripts/{greasyfork_id})"
44 return f"{', '.join(user_links)} ⇒ 📜 _{script_link}_"
45 except requests.exceptions.RequestException as e:
46 print(f"{url} 失败: {e}")
47 except json.JSONDecodeError as e:
48 print(f"解析脚本统计数据时出错: {e}")
49 return ''
50
51
52def process_script_ids(input_file):

Callers 1

process_script_idsFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected