summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2022-02-21 13:19:24 +0100
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2022-02-21 13:19:24 +0100
commit0645754d5742c955965d35cdbd617d550f959146 (patch)
tree5a8b8be4eff036c2f55d7b2892012b23c3092cb8
parent368daac4cd6a33352d92eddfe656e2f357275c8b (diff)
downloadquatuorbellefeuille.com-0645754d5742c955965d35cdbd617d550f959146.tar.xz
[wip] Generate RSS feed from concerts list
-rwxr-xr-xbuild-feed.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/build-feed.py b/build-feed.py
new file mode 100755
index 0000000..5b14326
--- /dev/null
+++ b/build-feed.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+
+from urllib.parse import urljoin
+from xml.etree.ElementTree import Element, SubElement, indent, tostring
+
+
+DOMAIN = 'quatuorbellefeuille.com'
+LANG = 'fr'
+
+
+LOCALIZED_TEXT = {
+ 'en': {
+ 'title': 'Bellefeuille Quartet',
+ 'indexpath': 'en/',
+ 'description': 'News from the Bellefeuille quartet',
+ },
+ 'fr': {
+ 'title': 'Quatuor Bellefeuille',
+ 'indexpath': '/',
+ 'description': 'Des nouvelles du quatuor Bellefeuille',
+ },
+}
+
+URL = f'https://{DOMAIN}'
+INDEX_URL = urljoin(URL, LOCALIZED_TEXT[LANG]['indexpath'])
+
+
+def text_element(tag, text, /, **kwargs):
+ elt = Element(tag, **kwargs)
+ elt.text = text
+ return elt
+
+
+rss = Element('rss', version='2.0')
+
+channel = SubElement(rss, 'channel')
+
+channel.extend((
+ text_element('title', LOCALIZED_TEXT[LANG]['title']),
+ text_element('link', INDEX_URL),
+ text_element('description', LOCALIZED_TEXT[LANG]['description']),
+))
+
+image = SubElement(channel, 'image')
+image.extend((
+ text_element('url', urljoin(URL, 'images/logo.svg')),
+ text_element('link', urljoin(INDEX_URL, 'concerts.html')),
+))
+
+channel.append(text_element('language', LANG))
+
+indent(rss)
+
+print(tostring(rss, encoding='utf-8', xml_declaration=True).decode())