summaryrefslogtreecommitdiff
path: root/build-feed.py
blob: 5b14326d5bc4dec30f9c7935e835401c8cdfb6be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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())