Forráskód Böngészése

Display a more useful message on error

jherve 1 éve
szülő
commit
6cfefac975

+ 2 - 2
src/de_quoi_parle_le_monde/internet_archive.py

@@ -1,4 +1,4 @@
-from attrs import frozen
+from attrs import frozen, field
 from typing import Optional, ClassVar, NewType
 from typing import Optional, ClassVar, NewType
 from datetime import date, datetime, timedelta
 from datetime import date, datetime, timedelta
 import cattrs
 import cattrs
@@ -90,7 +90,7 @@ class InternetArchiveSnapshotId:
 @frozen
 @frozen
 class InternetArchiveSnapshot:
 class InternetArchiveSnapshot:
     id: InternetArchiveSnapshotId
     id: InternetArchiveSnapshotId
-    text: str
+    text: str = field(repr=False)
 
 
 
 
 @frozen
 @frozen

+ 16 - 14
src/de_quoi_parle_le_monde/main.py

@@ -1,6 +1,7 @@
 from datetime import date, datetime, time, timedelta
 from datetime import date, datetime, time, timedelta
 import asyncio
 import asyncio
 from attrs import frozen
 from attrs import frozen
+import traceback
 
 
 from de_quoi_parle_le_monde.http import HttpClient
 from de_quoi_parle_le_monde.http import HttpClient
 from de_quoi_parle_le_monde.internet_archive import (
 from de_quoi_parle_le_monde.internet_archive import (
@@ -19,25 +20,17 @@ class ArchiveDownloader:
     def last_n_days_at_hours(n: int, hours: list[int]) -> list[datetime]:
     def last_n_days_at_hours(n: int, hours: list[int]) -> list[datetime]:
         return [
         return [
             datetime.combine(date.today() - timedelta(days=i), time(hour=h))
             datetime.combine(date.today() - timedelta(days=i), time(hour=h))
-            for i in range(1, n)
+            for i in range(0, n)
             for h in hours
             for h in hours
         ]
         ]
 
 
     @staticmethod
     @staticmethod
     async def find(ia, collection, dt):
     async def find(ia, collection, dt):
-        try:
-            return await ia.get_snapshot_id_closest_to(collection.url, dt)
-        except SnapshotNotYetAvailable as e:
-            print(f"Snapshot for {collection.url} @ {dt} not yet available")
-            return None
+        return await ia.get_snapshot_id_closest_to(collection.url, dt)
 
 
     @staticmethod
     @staticmethod
     async def parse(collection, snapshot):
     async def parse(collection, snapshot):
-        try:
-            return await collection.MainPageClass.from_snapshot(snapshot)
-        except AttributeError as e:
-            print(f"error while processing {id_closest}")
-            raise e
+        return await collection.MainPageClass.from_snapshot(snapshot)
 
 
     @staticmethod
     @staticmethod
     async def store(page, collection, storage, dt):
     async def store(page, collection, storage, dt):
@@ -61,12 +54,21 @@ class ArchiveDownloader:
 
 
     @classmethod
     @classmethod
     async def handle_snap(cls, ia, collection, storage, dt):
     async def handle_snap(cls, ia, collection, storage, dt):
-        id_closest = await cls.find(ia, collection, dt)
-        if id_closest is None:
+        try:
+            id_closest = await cls.find(ia, collection, dt)
+        except SnapshotNotYetAvailable as e:
+            print(f"Snapshot for {collection.url} @ {dt} not yet available")
             return
             return
 
 
         closest = await ia.fetch(id_closest)
         closest = await ia.fetch(id_closest)
-        main_page = await cls.parse(collection, closest)
+
+        try:
+            main_page = await cls.parse(collection, closest)
+        except Exception as e:
+            print(f"Error while processing {closest} from {collection} @ {dt}")
+            traceback.print_exception(e)
+            return
+
         await cls.store(main_page, collection, storage, dt)
         await cls.store(main_page, collection, storage, dt)