Browse Source

Some renaming

jherve 1 year ago
parent
commit
67a2f03714

+ 13 - 9
src/de_quoi_parle_le_monde/internet_archive.py

@@ -72,7 +72,7 @@ class CdxRequest:
 
 
 @frozen
-class InternetArchiveSnapshot:
+class InternetArchiveRemoteSnapshot:
     timestamp: Timestamp
     original: str
 
@@ -82,7 +82,9 @@ class InternetArchiveSnapshot:
 
     @staticmethod
     def from_record(rec: CdxRecord):
-        return InternetArchiveSnapshot(timestamp=rec.timestamp, original=rec.original)
+        return InternetArchiveRemoteSnapshot(
+            timestamp=rec.timestamp, original=rec.original
+        )
 
 
 @frozen
@@ -91,20 +93,22 @@ class InternetArchiveClient:
     session: HttpSession
     search_url: ClassVar[str] = "http://web.archive.org/cdx/search/cdx"
 
-    async def search_snapshots(self, req: CdxRequest) -> list[InternetArchiveSnapshot]:
-        def to_snapshot(line):
+    async def search_remote_snapshots(
+        self, req: CdxRequest
+    ) -> list[InternetArchiveRemoteSnapshot]:
+        def to_remote_snapshot(line):
             record = CdxRecord.parse_line(line)
-            return InternetArchiveSnapshot.from_record(record)
+            return InternetArchiveRemoteSnapshot.from_record(record)
 
         resp = await self.session.get(self.search_url, req.into_params())
 
-        return [to_snapshot(line) for line in resp.splitlines()]
+        return [to_remote_snapshot(line) for line in resp.splitlines()]
 
-    async def fetch(self, snap: InternetArchiveSnapshot) -> str:
+    async def fetch(self, snap: InternetArchiveRemoteSnapshot) -> str:
         resp = await self.session.get(snap.url)
         return resp
 
-    async def get_snapshot_closest_to(self, url, dt):
+    async def get_remote_snapshot_closest_to(self, url, dt):
         req = CdxRequest(
             url=url,
             from_=dt - timedelta(hours=6.0),
@@ -117,6 +121,6 @@ class InternetArchiveClient:
             filter="statuscode:200",
         )
 
-        all_snaps = await self.search_snapshots(req)
+        all_snaps = await self.search_remote_snapshots(req)
         closest = min(all_snaps, key=lambda s: abs(s.timestamp - dt))
         return closest

+ 4 - 4
src/de_quoi_parle_le_monde/le_monde.py

@@ -4,7 +4,7 @@ import cattrs
 import asyncio
 from bs4 import BeautifulSoup
 
-from de_quoi_parle_le_monde.internet_archive import InternetArchiveSnapshot
+from de_quoi_parle_le_monde.internet_archive import InternetArchiveRemoteSnapshot
 
 
 @frozen
@@ -35,7 +35,7 @@ class LeMondeMainArticle:
 
 @frozen
 class LeMondeMainPage:
-    snapshot: InternetArchiveSnapshot
+    snapshot: InternetArchiveRemoteSnapshot
     soup: BeautifulSoup
 
     def get_top_articles(self):
@@ -51,11 +51,11 @@ class LeMondeMainPage:
 
     @staticmethod
     async def from_content(
-        snapshot: InternetArchiveSnapshot, text: str
+        remote_snapshot: InternetArchiveRemoteSnapshot, text: str
     ) -> "LeMondeMainPage":
         loop = asyncio.get_event_loop()
         soup = await loop.run_in_executor(None, BeautifulSoup, text, "lxml")
-        return LeMondeMainPage(snapshot, soup)
+        return LeMondeMainPage(remote_snapshot, soup)
 
 
 @frozen

+ 3 - 1
src/de_quoi_parle_le_monde/main.py

@@ -23,7 +23,9 @@ class ArchiveDownloader:
             ia = InternetArchiveClient(session)
 
             async def handle_snap(dt):
-                closest = await ia.get_snapshot_closest_to(LeMondeArchive.url, dt)
+                closest = await ia.get_remote_snapshot_closest_to(
+                    LeMondeArchive.url, dt
+                )
                 closest_body = await ia.fetch(closest)
                 return await LeMondeMainPage.from_content(closest, closest_body)