From 364e1c5a799615a19a93af5df9dc0c7bbe3cb08b Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 11 Sep 2023 23:22:55 +0300 Subject: Add last build date --- app/server.py | 41 +++++++++++++++++++++++++++++++---------- plugins/FeedSinkPlugin.py | 25 ++++++++++++++----------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/app/server.py b/app/server.py index b4ebcf6..081c961 100644 --- a/app/server.py +++ b/app/server.py @@ -5,16 +5,26 @@ from tinydb import Query from app.DatabaseManager import database_manager -def feed_id_to_li(feed_id: str) -> str: - return f'
  • {feed_id}
  • ' +def feed_id_to_td(feed_id: str) -> str: + return f'{feed_id}' -def feed_ids_to_ul(feed_ids: list[str]) -> str: - if len(feed_ids) == 0: +def feed_last_build_date_to_td(last_build_date: str) -> str: + return f"{last_build_date}" + + +def feed_to_tr(feed: dict[str, str]) -> str: + return f'{feed_id_to_td(feed["feed_id"])}{feed_last_build_date_to_td(feed.get("feed_last_build_date", ""))}' + + +def feeds_to_table(feeds: list[dict[str, str]]) -> str: + if len(feeds) == 0: return "No feeds (yet). Add feeds by defining them in your Aggrofile. If you did that already, you might have to wait a bit for the data to propagate." - lis = [feed_id_to_li(feed_id) for feed_id in feed_ids] - return "" + trs: list[str] = [feed_to_tr(feed) for feed in feeds] + thead = f"FeedLast build date" + tbody = f'{"".join(trs)}' + return "" + thead + tbody + "
    " @bottle.route("/") @@ -23,8 +33,7 @@ def index(): raise Exception("Database is not initialized") Q = Query() - res = database_manager.feeds.all() - feeds_ids = [feed["feed_id"] for feed in res] + feeds = database_manager.feeds.all() bottle.response.set_header("content-type", "text/html") page = f""" @@ -46,13 +55,25 @@ def index(): h1 {{ margin-bottom: 0; }} + table {{ + width: 100%; + border-collapse: collapse; + }} + + table, th, td {{ + border: 1px solid #e0e0e0; + }} + + th, td {{ + padding: 8px; + }}

    Aggro

    Feed manipulator -

    List of feeds served here

    - {feed_ids_to_ul(feeds_ids)} +

    Feeds served at this address

    + {feeds_to_table(feeds)} """ diff --git a/plugins/FeedSinkPlugin.py b/plugins/FeedSinkPlugin.py index 6785a28..09eb572 100644 --- a/plugins/FeedSinkPlugin.py +++ b/plugins/FeedSinkPlugin.py @@ -1,3 +1,4 @@ +from datetime import datetime from typing import Any import xml.etree.ElementTree as ET @@ -37,15 +38,6 @@ class Plugin(PluginInterface): description = ET.SubElement(channel, "description") description.text = self.feed_description - # TODO favicons - # - # https://www.aaniwalli.fi/ - # - # https://www.google.com/s2/favicons?domain=https://www.aaniwalli.fi - # - # Ääniwalli - # - if favicon_url is not None: favicon_image_elem = ET.SubElement(channel, "image") favicon_link_elem = ET.SubElement(favicon_image_elem, "link") @@ -55,6 +47,13 @@ class Plugin(PluginInterface): favicon_title_elem = ET.SubElement(favicon_image_elem, "title") favicon_title_elem.text = self.feed_title + generator_elem = ET.SubElement(channel, "generator") + generator_elem.text = "https://github.com/jantuomi/aggro" + + last_build_date_elem = ET.SubElement(channel, "lastBuildDate") + now = datetime.now() + last_build_date_elem.text = now.strftime("%a, %d %b %Y %H:%M:%S +0000") + for item in items: item_elem = ET.SubElement(channel, "item") if item.title is not None: @@ -104,7 +103,11 @@ class Plugin(PluginInterface): }, ) - return ET.tostring(rss, "unicode") + return { + "feed_id": self.feed_id, + "feed_xml": ET.tostring(rss, "unicode"), + "feed_last_build_date": last_build_date_elem.text, + } def process(self, source_id: str | None, items: list[Item]) -> list[Item]: print(f"[FeedSinkPlugin#{self.id}] process called, n={len(items)}") @@ -117,6 +120,6 @@ class Plugin(PluginInterface): ret = self.build_xml(items) Q = Query() - database_manager.feeds.upsert({"feed_id": self.feed_id, "feed_xml": ret}, Q.feed_id == self.feed_id) # type: ignore + database_manager.feeds.upsert(ret, Q.feed_id == self.feed_id) # type: ignore print(f"[FeedSinkPlugin#{self.id}] processed") return [] -- cgit v1.3