💾 Archived View for gemini.sh0.xyz › development › atom.xml.py captured on 2023-04-26 at 12:54:52.
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
#!/usr/bin/env python3 import re import os import time from datetime import timezone from datetime import datetime import uuid log_dir = "/usr/local/gemini/log" #log_dir = "/home/jeff/gemini/log" url = "gemini://gemini.sh0.xyz/log" author = "jecxjo" title = "sh0.xyz captain's log" updated = datetime.strptime("1970-01-01 00:00:00.0000", "%Y-%m-%d %H:%M:%S.%f") feed_urn = uuid.uuid5(uuid.NAMESPACE_DNS, url) body = "" files = sorted(filter(lambda x: x.endswith(".gmi") and not x.endswith("index.gmi"), os.listdir(log_dir))) for f in files: with open(os.path.join(log_dir, f)) as file: contents = file.read() entry_title = re.findall("^# .*|$", contents)[0][1:].strip() entry_link = "{}/{}".format(url,f) entry_urn = uuid.uuid5(uuid.NAMESPACE_URL, entry_link) entry_published = re.findall("Published: \d\d\d\d-\d\d-\d\d \d\d:\d\d|$", contents)[0][10:].strip() entry_updated = re.findall("Updated: \d\d\d\d-\d\d-\d\d \d\d:\d\d|$", contents)[0][8:].strip() if not entry_published: continue if not entry_updated: entry_updated = entry_published entry_published = datetime.strptime(entry_published, '%Y-%m-%d %H:%M') entry_updated = datetime.strptime(entry_updated, '%Y-%m-%d %H:%M') body += " <entry>\n" body += " <title>{}</title>\n".format(entry_title) body += " <link href=\"{}\"/>\n".format(entry_link) body += " <id>urn:uuid:{}</id>\n".format(entry_urn) body += " <published>{}</published>\n".format(entry_published.isoformat('T')) body += " <updated>{}</updated>\n".format(entry_updated.isoformat('T')) body += " </entry>\n\n" if entry_updated > updated: updated = entry_updated # Printing print("20 text/xml\r") print("<?xml version=\"1.0\" encoding=\"utf-8\"?>") print("<feed xmlns=\"http://www.w3.org/2005/Atom\">") print("") print(" <title>{}</title>".format(title)) print(" <link href=\"{}\"/>".format(url)) print(" <updated>{}</updated>".format(updated.isoformat('T'))) print(" <author>") print(" <name>{}</name>".format(author)) print(" </author>") print(" <id>urn:uuid:{}</id>".format(feed_urn)) print("") print(body) print("</feed>")