diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-01 19:31:47 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-10 19:01:00 +0300 |
| commit | 398799de0c1826c3544eb6eec681fa48096932a0 (patch) | |
| tree | c2a2cf7fcf30276ffc432e7a1750efd6b7d2c8bf /app/FeedSourcePlugin.py | |
| parent | b7f129b29b8b8103336bfae265b3d5a0bc5ea03a (diff) | |
Refactor
Diffstat (limited to 'app/FeedSourcePlugin.py')
| -rw-r--r-- | app/FeedSourcePlugin.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/FeedSourcePlugin.py b/app/FeedSourcePlugin.py new file mode 100644 index 0000000..af686b9 --- /dev/null +++ b/app/FeedSourcePlugin.py @@ -0,0 +1,28 @@ +import feedparser # type: ignore +from typing import Any +from app.Item import Item +from app.PluginInterface import PluginInterface +from app.utils import get_param + + +class Plugin(PluginInterface): + def __init__(self, id: str, params: dict[str, Any]) -> None: + super().__init__(id, params) + self.feed_url: str = get_param("feed_url", params) + + print(f"[FeedSourcePlugin#{self.id}] initialized") + + def validate_input_n(self, n: int) -> bool: + return n == 0 + + def process(self, inputs: list[list[Item]]) -> list[Item]: + print(f"[FeedSourcePlugin#{self.id}] process called") + feed: Any = feedparser.parse(self.feed_url) # type: ignore + items: list[Item] = [] + for d in feed.entries: + items.append( + Item(title=d["title"], link=d["link"], description=d["description"]) + ) + + print(f"[FeedSourcePlugin#{self.id}] process returns items, n={len(items)}") + return items |
