aboutsummaryrefslogtreecommitdiff
path: root/blog/generate_feed.py
blob: a8eec2342fa61d5fe40ef734b72fdc7f1a32cf9c (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
#! /usr/bin/python3

import xml.etree.ElementTree as et

def main():
    tree = et.parse("articles.xml")
    root = tree.getroot()

    feed_xml = """<?xml version="1.0" encoding="UTF-8" ?>
<rss version=\"2.0\">
  <channel>
    <title>Nathan's shitty blog</title>
    <description>The coffee powered blog of chaos</description>
    <link>http://nathansmith117.beevomit.org/blog</link>
    <image>
      <url>http://nathansmith117.beevomit.org/images/icon.png</url>
      <title>Nathan's shitty blog</title>
      <link>http://nathansmith117.beevomit.org/blog</link>
    </image>
    """

    for item in root:
        with open(item.find("file").text, "r") as fp:
            feed_xml += """
    <item>
      <title>{title}</title>
      <link>http://nathansmith117.beevomit.org/blog#{name}</link>
      <pubDate>{date}</pubDate>
      <description>
        <![CDATA[
          {article}
        ]]>
      </description>
    </item>
            """.format(
                title=item.find("title").text,
                name=item.find("name").text,
                date=item.find("pubDate").text,
                article=fp.read()
            )

    feed_xml += """
  </channel>
</rss>
    """
    print(feed_xml)

if __name__ == "__main__":
    main()