diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/gen.py | 52 |
1 files changed, 51 insertions, 1 deletions
@@ -2,6 +2,8 @@ # vim: ts=4 sw=4 et set fileencoding=utf-8 from datetime import date, timedelta, datetime +import StringIO +import xml.etree.ElementTree as ET import os.path, errno, sys # CONFIG @@ -168,8 +170,10 @@ def render_date(cur_date, recurse=True): prev_date = find_surrounding_date(cur_date, timedelta(days=-1)) next_date = find_surrounding_date(cur_date, timedelta(days=1)) - render_page(cur_date, gather_all_entries(cur_date), prev_date, next_date) + entries = gather_all_entries(cur_date) + render_page(cur_date, entries, prev_date, next_date) print "Rendered page for: %s" % cur_date + update_feed(entries) if recurse and prev_date: render_date(prev_date, False) @@ -177,6 +181,52 @@ def render_date(cur_date, recurse=True): render_date(next_date, False) +def update_feed(entries): + feed_src = os.path.join(HTDOCS_DIR, "atom.xml") + + if os.path.isfile(feed_src): + doc = ET.ElementTree() + root = doc.parse(feed_src) + else: + doc = ET.ElementTree() + root = doc.parse(StringIO.StringIO("""<?xml version="1.0" encoding="utf-8"?> + <feed xmlns="http://www.w3.org/2005/Atom"> + <title>Comics</title> + <link href="https://comics.spline.de/atom.xml" rel="self" /> + <link href="https://comics.spline.de/" /> + <id>urn:uuid:12349d80-df99-1dea-b91C-0003939e0af6</id> + <updated>2003-12-13T18:30:02Z</updated></feed>""")) + + for entry in entries: + el = ET.SubElement(root, "{http://www.w3.org/2005/Atom}entry") + ET.SubElement(el, "{http://www.w3.org/2005/Atom}title").text = entry["comic"]["name"] + path = "https://comics.spline.de/%s" % entry["path"] + ET.SubElement(el, "{http://www.w3.org/2005/Atom}link").set("href", path) + c = ET.SubElement(el, "{http://www.w3.org/2005/Atom}content") + c.set("type", "xhtml") + d = ET.SubElement(c, "{http://www.w3.org/1999/xhtml}div") + i = ET.SubElement(d, "{http://www.w3.org/1999/xhtml}img") + i.set("src", path) + ET.SubElement(el, "{http://www.w3.org/2005/Atom}id").text = path + ET.SubElement(ET.SubElement(el, "{http://www.w3.org/2005/Atom}author"), "{http://www.w3.org/2005/Atom}name").text = "Spline" + fn = os.path.join(HTDOCS_DIR, entry["path"][1:]) + try: + tm = os.stat(fn) + ET.SubElement(el, "{http://www.w3.org/2005/Atom}updated").text = datetime.fromtimestamp(tm.st_mtime).strftime("%Y-%m-%dT%H:%M:%SZ") + except: + print "Not found: ", fn + + known = {} + for entry in root.iter("{http://www.w3.org/2005/Atom}entry"): + eid = entry.find("{http://www.w3.org/2005/Atom}id").text + if eid in known: + root.remove(entry) + known[eid] = True + + root.find("{http://www.w3.org/2005/Atom}updated").text = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") + doc.write(feed_src) + + def generate_basename(comic_id, date): return date.strftime("%%s/%%s/%Y-%m/%d") % (IMAGE_DIR, comic_id) |