Fix Github API rate limit message

This commit is contained in:
Howard20181 2023-01-20 06:12:13 +08:00
parent bbcb14caa4
commit 912a4c63ef

View File

@ -34,8 +34,7 @@ download_dir = Path.cwd().parent / \
tempScript = sys.argv[5]
android_api = sys.argv[6]
file_name = sys.argv[7]
print(
f"Generating {brand} download link: arch={arch} variant={variant}", flush=True)
print(f"Generating {brand} download link: arch={arch} variant={variant}", flush=True)
abi_map = {"x64": "x86_64", "arm64": "arm64"}
android_api_map = {"30": "11.0", "32": "12.1", "33": "13.0"}
release = android_api_map[android_api]
@ -45,7 +44,7 @@ if brand == "OpenGApps":
j = json.loads(res.content)
link = {i["name"]: i for i in j["archs"][abi_map[arch]]
["apis"][release]["variants"]}[variant]["zip"]
DATE=j["archs"][abi_map[arch]]["date"]
DATE = j["archs"][abi_map[arch]]["date"]
print(f"DATE={DATE}", flush=True)
except Exception:
print("Failed to fetch from OpenGApps API, fallbacking to SourceForge RSS...")
@ -64,18 +63,19 @@ elif brand == "MindTheGapps":
print(f"Failed to fetch from SourceForge RSS, fallbacking to Github API...", flush=True)
res = requests.get(f"https://api.github.com/repos/s1204IT/MindTheGappsBuilder/releases/latest")
json_data = json.loads(res.content)
headers = res.headers
x_ratelimit_remaining = headers["x-ratelimit-remaining"]
if res.status_code == 200:
assets = json_data["assets"]
for asset in assets:
if re.match(f'.*{release}.*{abi_map[arch]}.*\.zip$', asset["name"]):
link = asset["browser_download_url"]
elif res.status_code == 403:
break
elif res.status_code == 403 and x_ratelimit_remaining == '0':
message = json_data["message"]
print(f"Github API Error: {message}", flush=True)
headers = res.headers
headers_json = json.load(headers)
ratelimit_reset = headers_json["x-ratelimit-reset"]
ratelimit_reset = datetime.datetime.utcfromtimestamp(ratelimit_reset)
ratelimit_reset = headers["x-ratelimit-reset"]
ratelimit_reset = datetime.fromtimestamp(int(ratelimit_reset))
print(f"The current rate limit window resets in {ratelimit_reset}", flush=True)
exit(1)