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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#!/usr/bin/env python
# vim: set ts=4 sw=4 sts=4 et :
import markdown
import collections
from feedgen.feed import FeedGenerator
from dateutil import tz
import os
import datetime
import stat
fg = FeedGenerator()
url = "https://ouferr.at"
fg.id(url)
fg.description("Fansub per Wonder Egg Priority")
fg.title("Ou ferrat subs")
fg.author(name="Ou Ferrat")
fg.link(href=url+'/', rel='alternate')
fg.link(href=url+'/atom.xml', rel='self')
fg.language("ca")
fg.updated(datetime.datetime.now(tz.tzlocal()))
doc = ""
with open("header.html") as f:
header = f.read()
with open("postfooter.html") as f:
postfooter = f.read()
doc += header
for i in reversed(range(100)):
fn = f"{str(i).zfill(2)}.md"
#print(fn)
try:
with open(fn) as f:
entry = f.read()
except FileNotFoundError:
continue
head, body = entry.split("\n---\n\n", 1)
head = head.split("\n")
head = {k.strip(): v.strip() for k, v in [l.split(":", 1) for l in head]}
head = collections.defaultdict(lambda: "", head)
body = markdown.markdown(body)
html_fn = f"{str(i).zfill(2)}.html"
html = ("<article>\n" +
"<header>\n" +
f"<h2><a href='/{html_fn}'>{head['title']}</a></h2>\n" +
f"<time class='date'>{head['date']}</time>\n" +
"</header>\n" +
body +
"\n</article>\n")
doc += html
with open(html_fn, "w") as f:
f.write(header+html+postfooter)
fe = fg.add_entry(order='append')
fe.id(url+'/'+html_fn)
fe.title(head['title'].replace('<br>', '—'))
fe.content(html, type="html")
try: # crashing because of an invalid date would be sad
dt = datetime.datetime.fromisoformat(head['date']+":00+01:00")
fe.published(dt)
stats = os.stat(fn)
updated = datetime.datetime.fromtimestamp(stats[stat.ST_MTIME],
tz.tzlocal())
fe.updated(updated)
except ValueError as e:
print("error with date", e, head['date'])
pass
fg.rss_file('rss.xml')
fg.atom_file("atom.xml")
with open("index.html", "w") as f:
f.write(doc)
|