diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-02 00:38:23 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-10 19:01:00 +0300 |
| commit | 52418884284b5bf0919c48cf4b02c3bd23dc9e97 (patch) | |
| tree | 932b30bce805c5602c7cf49c1a8ffef05d8f6a18 /app/FeedSinkPlugin.py | |
| parent | 398799de0c1826c3544eb6eec681fa48096932a0 (diff) | |
Do stuff
Diffstat (limited to 'app/FeedSinkPlugin.py')
| -rw-r--r-- | app/FeedSinkPlugin.py | 62 |
1 files changed, 62 insertions, 0 deletions
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 + + +# <?xml version="1.0" encoding="UTF-8" ?> +# <rss version="2.0"> + +# <channel> +# <title>W3Schools Home Page</title> +# <link>https://www.w3schools.com</link> +# <description>Free web building tutorials</description> +# <item> +# <title>RSS Tutorial</title> +# <link>https://www.w3schools.com/xml/xml_rss.asp</link> +# <description>New RSS tutorial on W3Schools</description> +# </item> +# <item> +# <title>XML Tutorial</title> +# <link>https://www.w3schools.com/xml</link> +# <description>New XML tutorial on W3Schools</description> +# </item> +# </channel> + +# </rss> + + +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 [] |
