aboutsummaryrefslogtreecommitdiff
path: root/html/feed
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-05-18 20:31:14 -0600
committerFlorian Fischer <florian.fischer@muhq.space>2025-05-18 20:35:04 -0600
commitc7ff1c0a664803e9788a73b9edfbe4606aa2eee7 (patch)
tree9a4f2959aa5886c10df80e3a9bdfaebda0893369 /html/feed
parenta598e3b037da9f0354a9d306ae3e1dd6ac4ac48c (diff)
downloadmuhqs-game-c7ff1c0a664803e9788a73b9edfbe4606aa2eee7.tar.gz
muhqs-game-c7ff1c0a664803e9788a73b9edfbe4606aa2eee7.zip
add rss feed
Diffstat (limited to 'html/feed')
-rw-r--r--html/feed/create_feed.py61
-rw-r--r--html/feed/items/news_feed_available.xml6
2 files changed, 67 insertions, 0 deletions
diff --git a/html/feed/create_feed.py b/html/feed/create_feed.py
new file mode 100644
index 00000000..17f2afdf
--- /dev/null
+++ b/html/feed/create_feed.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+"""Create a rss feed from a list of item files"""
+
+import argparse
+from email.utils import parsedate_to_datetime, formatdate
+from datetime import datetime
+from string import Template
+import sys
+import xml.etree.ElementTree as ET
+
+FEED_HEAD = """<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0">
+<channel>
+<title>$title</title>
+<link>$link</link>
+<description>$description</description>
+<language>$language</language>
+<pubDate>$pubDate</pubDate>"""
+
+FEED_TAIL = """</channel>
+</rss>"""
+
+
+def item_date_to_epoch(item) -> int:
+ """return the time from epoch to the pubDate of an item"""
+ pub_date = item.find('pubDate')
+ date = parsedate_to_datetime(pub_date.text)
+ return date.timestamp()
+
+
+def main():
+ """read item files sort them and print a sorted rss feed"""
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--link', default='https://muhq.space/muhqs-game')
+ parser.add_argument('--title', default="Muhq's Game")
+ parser.add_argument('--description',
+ default="What is happening with muhq's game?")
+ parser.add_argument('--language', default='en')
+ parser.add_argument('--pubDate', default='Sun, 18 May 2025 20:21:20 -0600')
+ parser.add_argument('items', nargs='*')
+ args = parser.parse_args()
+
+ head = Template(FEED_HEAD)
+ print(head.substitute(**args.__dict__))
+
+ items = []
+ for item_path in args.items:
+ items.append(ET.parse(item_path))
+
+ items.sort(reverse=True, key=item_date_to_epoch)
+
+ last_build_date = formatdate(datetime.now().timestamp())
+ print(f'<lastBuildDate>{last_build_date}</lastBuildDate>')
+ for item in items:
+ item.write(sys.stdout, encoding='unicode')
+ print()
+ print(FEED_TAIL)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/html/feed/items/news_feed_available.xml b/html/feed/items/news_feed_available.xml
new file mode 100644
index 00000000..19b2d90d
--- /dev/null
+++ b/html/feed/items/news_feed_available.xml
@@ -0,0 +1,6 @@
+<item>
+<title>News feed available</title>
+<description>Stay informed about what is happening with muhq's game.</description>
+<link>https://muhq.space/muhqs-game</link>
+<pubDate>Sun, 18 May 2025 20:22:47 -0600</pubDate>
+</item>