book: add retry to download

This commit is contained in:
René Kijewski 2024-11-24 00:07:59 +01:00
parent e182022f87
commit 476a50d184

View File

@ -7,6 +7,7 @@ from io import StringIO
from json import load from json import load
from os import PathLike from os import PathLike
from pathlib import Path from pathlib import Path
from time import sleep
INDEX_HBS_DOMAIN = "api.github.com" INDEX_HBS_DOMAIN = "api.github.com"
@ -53,12 +54,17 @@ SIDEBAR_END = r"""
def update_theme(target: PathLike) -> None: def update_theme(target: PathLike) -> None:
with closing(HTTPSConnection(INDEX_HBS_DOMAIN, INDEX_HBS_PORT)) as conn: for i in reversed(range(3)):
conn.request(INDEX_HBS_PROTO, INDEX_HBS_PATH, INDEX_HBS_DATA, INDEX_HBS_HEADERS) with closing(HTTPSConnection(INDEX_HBS_DOMAIN, INDEX_HBS_PORT)) as conn:
res = conn.getresponse() conn.request(INDEX_HBS_PROTO, INDEX_HBS_PATH, INDEX_HBS_DATA, INDEX_HBS_HEADERS)
if res.status != 200: res = conn.getresponse()
raise Exception(f"Status={res.status!r}") if res.status == 200:
data = load(res) data = load(res)
break
if i != 0:
sleep(1.0)
else:
raise Exception(f"Status={res.status!r}")
if data["encoding"] != "base64": if data["encoding"] != "base64":
raise Exception(f'Encoding={data["encoding"]!r}') raise Exception(f'Encoding={data["encoding"]!r}')