瀏覽代碼

Review renaming

jherve 1 年之前
父節點
當前提交
23003f5f97

+ 10 - 12
src/de_quoi_parle_le_monde/internet_archive.py

@@ -70,7 +70,7 @@ class CdxRequest:
 
 
 @frozen
-class InternetArchiveRemoteSnapshot:
+class InternetArchiveSnapshotId:
     timestamp: Timestamp
     original: str
 
@@ -80,9 +80,7 @@ class InternetArchiveRemoteSnapshot:
 
     @staticmethod
     def from_record(rec: CdxRecord):
-        return InternetArchiveRemoteSnapshot(
-            timestamp=rec.timestamp, original=rec.original
-        )
+        return InternetArchiveSnapshotId(timestamp=rec.timestamp, original=rec.original)
 
 
 @frozen
@@ -91,22 +89,22 @@ class InternetArchiveClient:
     session: HttpSession
     search_url: ClassVar[str] = "http://web.archive.org/cdx/search/cdx"
 
-    async def search_remote_snapshots(
+    async def search_snapshots(
         self, req: CdxRequest
-    ) -> list[InternetArchiveRemoteSnapshot]:
-        def to_remote_snapshot(line):
+    ) -> list[InternetArchiveSnapshotId]:
+        def to_snapshot_id(line):
             record = CdxRecord.parse_line(line)
-            return InternetArchiveRemoteSnapshot.from_record(record)
+            return InternetArchiveSnapshotId.from_record(record)
 
         resp = await self.session.get(self.search_url, req.into_params())
 
-        return [to_remote_snapshot(line) for line in resp.splitlines()]
+        return [to_snapshot_id(line) for line in resp.splitlines()]
 
-    async def fetch(self, snap: InternetArchiveRemoteSnapshot) -> str:
+    async def fetch(self, snap: InternetArchiveSnapshotId) -> str:
         resp = await self.session.get(snap.url)
         return resp
 
-    async def get_remote_snapshot_closest_to(self, url, dt):
+    async def get_snapshot_id_closest_to(self, url, dt):
         req = CdxRequest(
             url=url,
             from_=dt - timedelta(hours=6.0),
@@ -119,6 +117,6 @@ class InternetArchiveClient:
             filter="statuscode:200",
         )
 
-        all_snaps = await self.search_remote_snapshots(req)
+        all_snaps = await self.search_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 InternetArchiveRemoteSnapshot
+from de_quoi_parle_le_monde.internet_archive import InternetArchiveSnapshotId
 
 
 @frozen
@@ -35,7 +35,7 @@ class LeMondeMainArticle:
 
 @frozen
 class LeMondeMainPage:
-    snapshot: InternetArchiveRemoteSnapshot
+    snapshot_id: InternetArchiveSnapshotId
     soup: BeautifulSoup
 
     def get_top_articles(self):
@@ -51,11 +51,11 @@ class LeMondeMainPage:
 
     @staticmethod
     async def from_content(
-        remote_snapshot: InternetArchiveRemoteSnapshot, text: str
+        snapshot_id: InternetArchiveSnapshotId, text: str
     ) -> "LeMondeMainPage":
         loop = asyncio.get_event_loop()
         soup = await loop.run_in_executor(None, BeautifulSoup, text, "lxml")
-        return LeMondeMainPage(remote_snapshot, soup)
+        return LeMondeMainPage(snapshot_id, soup)
 
 
 @frozen

+ 3 - 5
src/de_quoi_parle_le_monde/main.py

@@ -23,11 +23,9 @@ class ArchiveDownloader:
             ia = InternetArchiveClient(session)
 
             async def handle_snap(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)
+                id_closest = await ia.get_snapshot_id_closest_to(LeMondeArchive.url, dt)
+                closest_body = await ia.fetch(id_closest)
+                return await LeMondeMainPage.from_content(id_closest, closest_body)
 
             return await asyncio.gather(*[handle_snap(d) for d in dts])