summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgemfeed.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/gemfeed.py b/gemfeed.py
index 1200ada..7143263 100755
--- a/gemfeed.py
+++ b/gemfeed.py
@@ -4,6 +4,7 @@ import datetime
import glob
import os
import os.path
+import re
import stat
import urllib.parse
@@ -93,13 +94,30 @@ def populate_entry_from_file(filename, base_url, entry):
url = urljoin(base_url, os.path.basename(filename))
entry.guid(url)
entry.link(href=url, rel="alternate")
- updated = os.path.getctime(filename)
- updated = datetime.datetime.fromtimestamp(updated, tz=datetime.timezone.utc)
+ updated = get_update_time(filename)
entry.updated(updated)
default_title = os.path.splitext(os.path.basename(filename))[0]
title = extract_first_heading(filename, default_title)
entry.title(title)
+def get_update_time(filename):
+ """
+ Return an update time for a Gemini file.
+
+ If the filename begins with an ISO8601 date stamp, that date
+ (with a time of midnight) will be used. Otherwise, the file
+ "creation time" (which in unix is actually the time of last
+ metadata update) will be used instead as a best estimate.
+ """
+ # Check for leading YYYY-MM-DD
+ basename = os.path.basename(filename)
+ if re.search("^[0-9]{4}-[01][0-9]-[0-3][0-9]", basename):
+ date = basename[0:10] + " Z" # Add UTC marker
+ return datetime.datetime.strptime(date, "%Y-%m-%d %z")
+ else:
+ updated = os.path.getctime(filename)
+ return datetime.datetime.fromtimestamp(updated, tz=datetime.timezone.utc)
+
def build_feed(directory, base_url, output="atom.xml", n=10, title="",
subtitle="", author="", email="", verbose=False):
"""