aboutsummaryrefslogtreecommitdiffstats
path: root/app/FeedSourcePlugin.py
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2023-09-03 19:07:30 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2023-09-10 19:01:00 +0300
commit7f2e5ee5bf59e5814d62990401714e01cd69ba07 (patch)
tree0f3f9fcba77ccf45d81f6090df0195c7f34e98d3 /app/FeedSourcePlugin.py
parent7c90b13a7eaf520126a40180f932125240b46364 (diff)
Refactor plugins to own dir
Diffstat (limited to 'app/FeedSourcePlugin.py')
-rw-r--r--app/FeedSourcePlugin.py58
1 files changed, 0 insertions, 58 deletions
diff --git a/app/FeedSourcePlugin.py b/app/FeedSourcePlugin.py
deleted file mode 100644
index 575e5d6..0000000
--- a/app/FeedSourcePlugin.py
+++ /dev/null
@@ -1,58 +0,0 @@
-import feedparser # type: ignore
-from typing import Any
-from app.Item import Item, ItemEnclosure
-from app.PluginInterface import Params, PluginInterface
-from app.utils import ItemDict, get_param
-
-
-class Plugin(PluginInterface):
- def __init__(self, id: str, params: Params) -> None:
- super().__init__(id, params)
- self.feed_url: str = get_param("feed_url", params)
-
- print(f"[FeedSourcePlugin#{self.id}] initialized")
-
- def process(self, source_id: str | None, items: list[Item]) -> list[Item]:
- print(f"[FeedSourcePlugin#{self.id}] process called")
- if source_id is not None:
- raise Exception(
- f"FeedSourcePlugin#{self.id} can only be scheduled, trying to process items from ItemSource {source_id}"
- )
-
- feed: Any = feedparser.parse(self.feed_url) # type: ignore
- result_items: list[Item] = []
- if "bozo" in feed and feed["bozo"] == 1:
- raise Exception(
- f"[FeedSourcePlugin#{self.id}] malformed XML in feed {self.feed_url}"
- )
-
- for _d in feed.entries:
- d: ItemDict = _d
- item_enclosures: list[ItemEnclosure] = []
- for _e in d["enclosures"]:
- e: dict[str, str] = _e # type: ignore
- item_enclosures.append(
- ItemEnclosure(
- length=e["length"],
- type=e["type"],
- url=e["href"],
- )
- )
-
- result_items.append(
- Item(
- title=d.get("title", None), # type: ignore
- link=d.get("link", None), # type: ignore
- description=d.get("description", None), # type: ignore
- author=d.get("author", None), # type: ignore
- pub_date=d.get("published_parsed", None), # type: ignore
- category=d.get("category", None), # type: ignore
- comments=d.get("comments"), # type: ignore
- enclosures=item_enclosures,
- )
- )
-
- print(
- f"[FeedSourcePlugin#{self.id}] process returns items, n={len(result_items)}"
- )
- return result_items