From e05dfe63724ae4aa4845c6fb5e7f8d5aa0974e16 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 3 Sep 2023 17:56:52 +0300 Subject: Implement RSS spec stuff --- app/FeedSourcePlugin.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'app/FeedSourcePlugin.py') diff --git a/app/FeedSourcePlugin.py b/app/FeedSourcePlugin.py index 7690c8d..575e5d6 100644 --- a/app/FeedSourcePlugin.py +++ b/app/FeedSourcePlugin.py @@ -1,12 +1,12 @@ import feedparser # type: ignore from typing import Any -from app.Item import Item -from app.PluginInterface import PluginInterface -from app.utils import get_param +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: dict[str, Any]) -> None: + def __init__(self, id: str, params: Params) -> None: super().__init__(id, params) self.feed_url: str = get_param("feed_url", params) @@ -16,7 +16,7 @@ class Plugin(PluginInterface): 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 source {source_id}" + 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 @@ -26,9 +26,30 @@ class Plugin(PluginInterface): f"[FeedSourcePlugin#{self.id}] malformed XML in feed {self.feed_url}" ) - for d in feed.entries: + 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["title"], link=d["link"], description=d["description"]) + 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( -- cgit v1.3