]> git.rocketbowman.com Git - nom.git/commitdiff
move fetch implementation into flitem
authorKyle Bowman <kyle+github@rocketbowman.com>
Mon, 20 Jan 2025 21:24:14 +0000 (16:24 -0500)
committerKyle Bowman <kyle+github@rocketbowman.com>
Mon, 20 Jan 2025 21:24:14 +0000 (16:24 -0500)
src/nom/feed.py

index 11a7f7c1c5dc9d01d8d6e7bfc0b08889c3e64c16..923f9dece94f52a42b6ad8f49799b0cfc243b353 100644 (file)
@@ -39,8 +39,17 @@ class FeedListItem(NomListItem):
     def to_feed(self):
         return Feed(self.url)
 
-    def fetch_feed(self):
-        pass
+    def fetch_feed(self, save_dir: Path):
+        if not os.path.exists(save_dir):
+            os.makedirs(save_dir)
+
+        filename = url2filename(self.url)
+        path = save_dir / filename
+        with open(path, 'w') as f:
+            # TODO: URL Error Handling
+            r = requests.get(self.url)
+            f.write(r.text)
+        print(f"{path} updated")
 
 
 class FeedList(NomList):
@@ -56,14 +65,5 @@ class FeedList(NomList):
         return cls(file.name, urls) 
 
     def fetch_feeds(self, save_dir: Path):
-        if not os.path.exists(save_dir):
-            os.makedirs(save_dir)
-
         for flitem in self.items:
-            filename = url2filename(flitem.url)
-            path = save_dir / filename
-            with open(path, 'w') as f:
-                # TODO: URL Error Handling
-                r = requests.get(flitem.url)
-                f.write(r.text)
-            print(f"{path} updated")
\ No newline at end of file
+            flitem.fetch_feed(save_dir)
\ No newline at end of file