aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2023-09-11 23:22:55 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2023-09-11 23:22:55 +0300
commit364e1c5a799615a19a93af5df9dc0c7bbe3cb08b (patch)
treef85036a318b229095429e87c463c1ee7640cc5f0
parent8430864a0f4160fe8a5074c5cdd1ef2ba49bdf53 (diff)
Add last build date
-rw-r--r--app/server.py41
-rw-r--r--plugins/FeedSinkPlugin.py25
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'<li><a href="/{feed_id}">{feed_id}</a></li>'
+def feed_id_to_td(feed_id: str) -> str:
+ return f'<td><a href="/{feed_id}">{feed_id}</a></td>'
-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"<td>{last_build_date}</td>"
+
+
+def feed_to_tr(feed: dict[str, str]) -> str:
+ return f'<tr>{feed_id_to_td(feed["feed_id"])}{feed_last_build_date_to_td(feed.get("feed_last_build_date", ""))}</tr>'
+
+
+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 "<ul>" + "".join(lis) + "</ul>"
+ trs: list[str] = [feed_to_tr(feed) for feed in feeds]
+ thead = f"<thead><tr><td>Feed</td><td>Last build date</td></tr></thead>"
+ tbody = f'<tbody>{"".join(trs)}</tbody>'
+ return "<table>" + thead + tbody + "</table>"
@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;
+ }}
</style>
</head>
<body>
<h1>Aggro</h2>
<i>Feed manipulator</i>
- <h2>List of feeds served here</h2>
- {feed_ids_to_ul(feeds_ids)}
+ <h2>Feeds served at this address</h2>
+ {feeds_to_table(feeds)}
</body>
</html>
"""
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
- # <image>
- # <link>https://www.aaniwalli.fi/</link>
- # <url>
- # https://www.google.com/s2/favicons?domain=https://www.aaniwalli.fi
- # </url>
- # <title>Ääniwalli</title>
- # </image>
-
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 []