diff options
author | Arjun Satarkar <me@arjunsatarkar.net> | 2023-07-30 20:57:06 +0000 |
---|---|---|
committer | Arjun Satarkar <me@arjunsatarkar.net> | 2023-07-30 21:01:00 +0000 |
commit | 1910ead6204cb37e0a44b519e96eb1c526afffda (patch) | |
tree | 80ee7917db376a642ef0fb58f0aa4417f14a828f | |
parent | 4e6d02e4ae9a9718e15e6b5c1328f28eea444e75 (diff) | |
download | tagrss-1910ead6204cb37e0a44b519e96eb1c526afffda.tar tagrss-1910ead6204cb37e0a44b519e96eb1c526afffda.tar.gz tagrss-1910ead6204cb37e0a44b519e96eb1c526afffda.zip |
Avoid unnecessary code in sqlite3 connection context manager
-rw-r--r-- | tagrss.py | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -75,8 +75,8 @@ class TagRss: epoch_downloaded: int, tags: list[str], ) -> int: + feed_title: str = parsed_feed.feed.get("title", "") # type: ignore with self.connection: - feed_title: str = parsed_feed.feed.get("title", "") # type: ignore try: self.connection.execute( "INSERT INTO feeds(source, title) VALUES(?, ?);", @@ -91,7 +91,7 @@ class TagRss: "INSERT INTO feed_tags(feed_id, tag) VALUES(?, ?);", ((feed_id, tag) for tag in tags), ) - self.store_feed_entries(feed_id, parsed_feed, epoch_downloaded) + self.store_feed_entries(feed_id, parsed_feed, epoch_downloaded) return feed_id def get_entries( @@ -200,18 +200,18 @@ class TagRss: "title": row[2], } if get_tags: + feed_ids = feeds.keys() + placeholder_str = ",".join(["?"] * len(feed_ids)) with self.connection: - feed_ids = feeds.keys() - placeholder_str = ",".join(["?"] * len(feed_ids)) resp = self.connection.execute( f"SELECT feed_id, tag FROM feed_tags WHERE feed_id in ({placeholder_str});", (*feed_ids,), ).fetchall() - for row in resp: - try: - feeds[row[0]]["tags"].append(row[1]) - except KeyError: - feeds[row[0]]["tags"] = [row[1]] + for row in resp: + try: + feeds[row[0]]["tags"].append(row[1]) + except KeyError: + feeds[row[0]]["tags"] = [row[1]] result: list[dict[str, typing.Any]] = [] for item in feeds.items(): feed = { |