From 87b58077af6747ded84c0a07e23a55cca493b2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B8=A2=E4=BD=8E=E5=90=B8?= Date: Sat, 13 Apr 2024 23:41:01 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20=E6=96=B0=E5=A2=9E=E9=87=8D?= =?UTF-8?q?=E8=A9=A6=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoBuild/nrdlist.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/AutoBuild/nrdlist.py b/AutoBuild/nrdlist.py index 995e39a..de056f7 100644 --- a/AutoBuild/nrdlist.py +++ b/AutoBuild/nrdlist.py @@ -132,16 +132,23 @@ class Phase4: self.data[date] = r.text.splitlines()[2:-2] async def run(self): - await self.fetch() + for i in range(5): + try: + await self.fetch() + except httpx.ReadTimeout: + logger.error("Phase4: Timeout, retrying") + continue + finally: + break -async def write_files(data: List[dict]): +async def write_files(datalist: List[Dict[str, List[str]]]): base_path = pathlib.Path("nrd") if not base_path.exists(): base_path.mkdir() combined_data: Dict[str, set] = {} - for data in [ph4.data]: + for data in datalist: for key, value in data.items(): if key not in combined_data: combined_data[key] = set(value) @@ -168,7 +175,6 @@ if __name__ == "__main__": ph4 = Phase4() task = [ph1.run(loop), ph2.run(), ph3.run(), ph4.run()] - loop.run_until_complete(asyncio.gather(*task)) logger.info("Download Complete, Now writing") loop.run_until_complete(write_files([ph1.data, ph2.data, ph3.data, ph4.data]))