summaryrefslogtreecommitdiff
path: root/generate_feed.py
blob: aa153b04c8d823330072433ade6cc7a2c47a1140 (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
#!/usr/bin/env python3

from datetime import datetime

import lxml.html
from lxml import etree

document = lxml.html.parse("static_tmp/releases.html").getroot()
releases = document.body.cssselect("#changelog article")

updated = None
entries = []

for release in releases:
    title = release.attrib["id"]
    time = datetime.strptime(title, "%Y.%m.%d.%H").isoformat() + "Z"
    if updated is None:
        updated = time
    content = [etree.tostring(e).decode() for e in release.getchildren()[1:]]
    entry = f"""\
    <entry>
        <id>https://grapheneos.org/releases#{title}</id>
        <link href="https://grapheneos.org/releases#{title}"/>
        <title>{title}</title>
        <updated>{time}</updated>
        <published>{time}</published>
        <content type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">
                {"".join(content)}
            </div>
        </content>
    </entry>"""
    entries.append(entry)

feed = f"""<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id>https://grapheneos.org/releases#changelog</id>
    <link href="https://grapheneos.org/releases#changelog"/>
    <link rel="self" href="https://grapheneos.org/releases.atom"/>
    <icon>https://grapheneos.org/favicon.ico</icon>
    <title>GrapheneOS changelog</title>
    <updated>{updated}</updated>
    <author>
        <name>GrapheneOS</name>
        <email>contact@grapheneos.org</email>
        <uri>https://grapheneos.org/</uri>
    </author>
    {"".join(entries)}
</feed>
"""

with open("static_tmp/releases.atom", "w") as f:
    f.write(feed)