From 476a50d184b2f07fb700cb9da5e48cd140211cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sun, 24 Nov 2024 00:07:59 +0100 Subject: [PATCH] book: add retry to download --- book/update-theme.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/book/update-theme.py b/book/update-theme.py index 54b4a08b..0a4ad48d 100755 --- a/book/update-theme.py +++ b/book/update-theme.py @@ -7,6 +7,7 @@ from io import StringIO from json import load from os import PathLike from pathlib import Path +from time import sleep INDEX_HBS_DOMAIN = "api.github.com" @@ -53,12 +54,17 @@ SIDEBAR_END = r""" def update_theme(target: PathLike) -> None: - with closing(HTTPSConnection(INDEX_HBS_DOMAIN, INDEX_HBS_PORT)) as conn: - conn.request(INDEX_HBS_PROTO, INDEX_HBS_PATH, INDEX_HBS_DATA, INDEX_HBS_HEADERS) - res = conn.getresponse() - if res.status != 200: - raise Exception(f"Status={res.status!r}") - data = load(res) + for i in reversed(range(3)): + with closing(HTTPSConnection(INDEX_HBS_DOMAIN, INDEX_HBS_PORT)) as conn: + conn.request(INDEX_HBS_PROTO, INDEX_HBS_PATH, INDEX_HBS_DATA, INDEX_HBS_HEADERS) + res = conn.getresponse() + if res.status == 200: + data = load(res) + break + if i != 0: + sleep(1.0) + else: + raise Exception(f"Status={res.status!r}") if data["encoding"] != "base64": raise Exception(f'Encoding={data["encoding"]!r}')