From 5dc6a6966bb950cb19439e0dc57f77a630254f19 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 14 Feb 2021 20:26:34 +0000 Subject: Pelican-ize --- extract.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'extract.py') diff --git a/extract.py b/extract.py index 9466769..ab77f01 100755 --- a/extract.py +++ b/extract.py @@ -40,8 +40,11 @@ attachment_query = ''' filename, time ''' -def isotime(t): - return None if t == 0 else time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(t)) +markdown_header = '''\ +Date: {0.isotime} +Title: {0.name} + +'''.format def attachment_link(row): h = lambda whatever: hashlib.sha1(whatever.encode()).hexdigest() @@ -50,7 +53,7 @@ def attachment_link(row): fn2 = os.path.splitext(row["filename"])[1] return \ os.path.join("attachments", "wiki", h1[:3], h1, h2 + fn2), \ - os.path.join("pelican", "content", urllib.parse.quote(row.id, ""), urllib.parse.quote(row.filename, "")) + os.path.join("pelican", "content", urllib.parse.quote(row.id, ""), row.filename) class Filter: @@ -68,9 +71,14 @@ class Filter: return True class Row(sqlite3.Row): + def __getattr__(self, name): return self[name] + @property + def isotime(self): + return time.strftime("%Y-%m-%d %H:%M", time.gmtime(self.time)) + def main(): for dn in ("wiki", "pelican"): @@ -92,7 +100,7 @@ def main(): print(slug, row.version) with open("wiki/{}.trac".format(slug), "w") as f: f.write(row.text) - md = trac2md.WikiToMD(row.text, slug) + md = markdown_header(row) + trac2md.WikiToMD(row.text, slug) with open("pelican/content/{}.md".format(slug), "w") as f: f.write(md) -- cgit v1.2.3