abort apk that fails to download
This commit is contained in:
parent
67d265d2e6
commit
9027220508
1 changed files with 23 additions and 2 deletions
|
|
@ -1,12 +1,16 @@
|
||||||
import http.client
|
import http.client
|
||||||
|
|
||||||
|
# import requests
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def download_apk(sha256: str, api_key: str, logfile: Path | None = None) -> bytes:
|
def download_apk(
|
||||||
while True:
|
sha256: str, api_key: str, logfile: Path | None = None
|
||||||
|
) -> bytes | None:
|
||||||
|
for _ in range(3):
|
||||||
try:
|
try:
|
||||||
conn = http.client.HTTPSConnection("androzoo.uni.lu")
|
conn = http.client.HTTPSConnection("androzoo.uni.lu")
|
||||||
conn.request("GET", f"/api/download?apikey={api_key}&sha256={sha256}")
|
conn.request("GET", f"/api/download?apikey={api_key}&sha256={sha256}")
|
||||||
|
|
@ -15,6 +19,16 @@ def download_apk(sha256: str, api_key: str, logfile: Path | None = None) -> byte
|
||||||
raise RuntimeError(f"Failled to download APK {sha256}: {resp.reason}")
|
raise RuntimeError(f"Failled to download APK {sha256}: {resp.reason}")
|
||||||
data = resp.read()
|
data = resp.read()
|
||||||
return data
|
return data
|
||||||
|
# resp = requests.get(
|
||||||
|
# "https://androzoo.uni.lu/api/download",
|
||||||
|
# params={
|
||||||
|
# b"apikey": api_key.encode("utf-8"),
|
||||||
|
# b"sha256": sha256.encode("utf-8"),
|
||||||
|
# },
|
||||||
|
# )
|
||||||
|
# if resp.status_code != 200:
|
||||||
|
# raise RuntimeError(f"Failled to download APK {sha256}: {resp.reason}")
|
||||||
|
# return resp.content
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
delay = random.randint(1, 6)
|
delay = random.randint(1, 6)
|
||||||
log = f"[{datetime.today().strftime('%Y-%m-%d %H:%M:%S')}] Failed to download {sha256}: {e}, retry in {delay}s"
|
log = f"[{datetime.today().strftime('%Y-%m-%d %H:%M:%S')}] Failed to download {sha256}: {e}, retry in {delay}s"
|
||||||
|
|
@ -24,3 +38,10 @@ def download_apk(sha256: str, api_key: str, logfile: Path | None = None) -> byte
|
||||||
else:
|
else:
|
||||||
print(log)
|
print(log)
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
|
log = f"[{datetime.today().strftime('%Y-%m-%d %H:%M:%S')}] Failed to download {sha256}, abort"
|
||||||
|
if logfile:
|
||||||
|
with logfile.open("a") as file:
|
||||||
|
file.write(f"{log}\n")
|
||||||
|
else:
|
||||||
|
print(log)
|
||||||
|
return None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue