forked from sirvaliance/crypto.is
-
Notifications
You must be signed in to change notification settings - Fork 1
/
makerss.py
executable file
·52 lines (38 loc) · 1.42 KB
/
makerss.py
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
#!/usr/bin/python
import os
bloglist = open('/web/crypto.is/templates/bloglist.txt', 'r')
lines = bloglist.readlines()
posts = []
for p in lines:
f = open('/web/crypto.is/templates/blog/' + p.strip() + '.html', 'r')
posts.append((p.strip(), f.readlines()))
rss = open('tmp-news.xml', 'w')
rss.write("""<?xml version="1.0\"?>
<rss version=\"2.0\">
<channel>
<title>crypto.is</title>
<link>https://crypto.is</link>
<description></description>\n\n""")
def indexOfCon(item, array):
return array.index([i for i in array if item in i][0])
for p in posts:
rss.write("\t<item>\n")
rss.write("\t\t<guid>https://crypto.is/blog/")
rss.write(p[0])
rss.write("</guid>\n")
lines = p[1]
title = [i for i in lines if '<h1>' in i][0].replace('</', '').replace('<', '').replace('h1>', '').strip()
rss.write("\t\t<title>")
rss.write(title)
rss.write("</title>\n")
pubdate = [i for i in lines if 'blogdate' in i][0].replace('<div class="blogdate">', '').replace('</div>', '').strip()
rss.write("\t\t<pubDate>")
rss.write(pubdate)
rss.write("</pubDate>\n")
contentlines = lines[indexOfCon('blogdate', lines) + 1 : indexOfCon('{% end', lines)]
rss.write("\t\t<description><![CDATA[\n")
rss.write("".join(contentlines))
rss.write("\n\t\t]]></description>\n")
rss.write("\t</item>\n\n")
rss.write("</channel>")
rss.write("</rss>")