From 52418884284b5bf0919c48cf4b02c3bd23dc9e97 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 2 Sep 2023 00:38:23 +0300 Subject: Do stuff --- app/FeedSinkPlugin.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 app/FeedSinkPlugin.py (limited to 'app/FeedSinkPlugin.py') diff --git a/app/FeedSinkPlugin.py b/app/FeedSinkPlugin.py new file mode 100644 index 0000000..c35a811 --- /dev/null +++ b/app/FeedSinkPlugin.py @@ -0,0 +1,62 @@ +from typing import Any +from app.Item import Item +from app.PluginInterface import PluginInterface +from app.utils import get_param +import xml.etree.ElementTree as ET + + +# +# + +# +# W3Schools Home Page +# https://www.w3schools.com +# Free web building tutorials +# +# RSS Tutorial +# https://www.w3schools.com/xml/xml_rss.asp +# New RSS tutorial on W3Schools +# +# +# XML Tutorial +# https://www.w3schools.com/xml +# New XML tutorial on W3Schools +# +# + +# + + +class Plugin(PluginInterface): + def __init__(self, id: str, params: dict[str, Any]) -> None: + super().__init__(id, params) + self.feed_name: str = get_param("feed_name", params) + print(f"[FeedSinkPlugin#{self.id}] initialized") + + def build_xml(self, items: list[Item]): + rss = ET.Element("rss", {"version": "2.0"}) + channel = ET.SubElement(rss, "channel") + title = ET.SubElement(channel, "title") + title.text = "channel title" + link = ET.SubElement(channel, "link") + link.text = "channel link" + description = ET.SubElement(channel, "description") + description.text = "channel description" + + for item in items: + item_elem = ET.SubElement(channel, "item") + item_title = ET.SubElement(item_elem, "title") + item_title.text = item.title + item_link = ET.SubElement(item_elem, "link") + item_link.text = item.link + item_description = ET.SubElement(item_elem, "description") + item_description.text = item.description + + return ET.tostring(rss, "unicode") + + def process(self, items: list[Item]) -> list[Item]: + print(f"[FeedSinkPlugin#{self.id}] process called, n={len(items)}") + ret = self.build_xml(items) + print(f"[FeedSinkPlugin#{self.id}] process returning XML:") + print(ret) + return [] -- cgit v1.3