z230
This commit is contained in:
@@ -77,13 +77,31 @@ query ClinicRequestDetail_GetPatientRequest2($requestId: UUID!) {
|
||||
"""
|
||||
|
||||
|
||||
RETRY_ATTEMPTS = 5
|
||||
RETRY_DELAY = 3 # sekund mezi pokusy
|
||||
|
||||
|
||||
def extract_filename_from_url(url: str) -> str:
|
||||
try:
|
||||
return url.split("/")[-1].split("?")[0]
|
||||
except:
|
||||
except Exception:
|
||||
return "unknown_filename"
|
||||
|
||||
|
||||
def download_with_retry(url: str) -> bytes:
|
||||
for attempt in range(1, RETRY_ATTEMPTS + 1):
|
||||
try:
|
||||
r = requests.get(url, timeout=60)
|
||||
if r.status_code == 200:
|
||||
return r.content
|
||||
safe_print(f" ⚠️ HTTP {r.status_code}, pokus {attempt}/{RETRY_ATTEMPTS}")
|
||||
except Exception as e:
|
||||
safe_print(f" ⚠️ Chyba stahování (pokus {attempt}/{RETRY_ATTEMPTS}): {e}")
|
||||
if attempt < RETRY_ATTEMPTS:
|
||||
time.sleep(RETRY_DELAY)
|
||||
raise RuntimeError(f"Stahování selhalo po {RETRY_ATTEMPTS} pokusech")
|
||||
|
||||
|
||||
def read_token(p: Path) -> str:
|
||||
tok = p.read_text(encoding="utf-8").strip()
|
||||
return tok.split(" ", 1)[1] if tok.startswith("Bearer ") else tok
|
||||
@@ -142,9 +160,8 @@ def main():
|
||||
|
||||
url = m.get("downloadUrl")
|
||||
if url:
|
||||
att_r = requests.get(url, timeout=30)
|
||||
if att_r.status_code == 200:
|
||||
content = att_r.content
|
||||
content = download_with_retry(url)
|
||||
if content:
|
||||
filename = extract_filename_from_url(url)
|
||||
|
||||
cur.execute("""
|
||||
|
||||
Reference in New Issue
Block a user