aboutsummaryrefslogtreecommitdiff
path: root/tagrss.py
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2023-08-03 13:33:36 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2023-08-03 13:33:36 +0000
commit0e120e5221478a3140e09de717ec8e0ff2d5178a (patch)
tree2c963a43dec1d9156165846c1621e767d225c872 /tagrss.py
parentc658002cad0c9b60b28dff8095a6682a43cd10d1 (diff)
downloadtagrss-0e120e5221478a3140e09de717ec8e0ff2d5178a.tar
tagrss-0e120e5221478a3140e09de717ec8e0ff2d5178a.tar.gz
tagrss-0e120e5221478a3140e09de717ec8e0ff2d5178a.zip
Simplify process to update feeds (i.e. fetch & store new entries)
Diffstat (limited to 'tagrss.py')
-rw-r--r--tagrss.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/tagrss.py b/tagrss.py
index 5785fbb..d113a96 100644
--- a/tagrss.py
+++ b/tagrss.py
@@ -53,10 +53,6 @@ Epoch = int
ParsedFeed = feedparser.FeedParserDict
-class StorageProvider(abc.ABC):
- pass
-
-
@dataclasses.dataclass(kw_only=True)
class PartialFeed:
id: typing.Optional[FeedId] = None
@@ -75,6 +71,10 @@ class Entry:
epoch_updated: Epoch
+class StorageProvider(abc.ABC):
+ pass
+
+
class SqliteStorageProvider(StorageProvider):
def __init__(self, storage_path: str | pathlib.Path):
self.__raw_connection = sqlite3.connect(storage_path, check_same_thread=False)
@@ -392,7 +392,7 @@ class TagRss:
def __init__(self, *, storage_path: str | pathlib.Path):
self.__storage = SqliteStorageProvider(storage_path)
- def fetch_and_parse_feed(self, source) -> tuple[ParsedFeed, int]:
+ def __fetch_and_parse_feed(self, source) -> tuple[ParsedFeed, Epoch]:
response = requests.get(source)
epoch_downloaded: int = int(time.time())
if response.status_code != requests.codes.ok:
@@ -412,7 +412,7 @@ class TagRss:
source: str,
tags: list[str],
) -> int:
- parsed, epoch_downloaded = self.fetch_and_parse_feed(source)
+ parsed, epoch_downloaded = self.__fetch_and_parse_feed(source)
title: str = parsed.feed.get("title", "") # type: ignore
feed_id = self.__storage.store_feed(source=source, title=title, tags=tags)
self.__storage.store_entries(
@@ -493,6 +493,11 @@ class TagRss:
included_feeds=included_feeds, included_tags=included_tags
)
+ def update_feed(self, feed_id: FeedId) -> None:
+ source = self.get_feed_source(feed_id)
+ parsed, epoch_downloaded = self.__fetch_and_parse_feed(source)
+ self.store_feed_entries(parsed, feed_id, epoch_downloaded)
+
def store_feed_entries(
self, parsed: ParsedFeed, feed_id: FeedId, epoch_downloaded: int
):