From ad1cc0517983e599897929b4c94463bf2af78f7c Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 14 Feb 2021 05:49:45 +0000 Subject: Calculate attachment links Not using these yet --- tools/extract.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'tools/extract.py') diff --git a/tools/extract.py b/tools/extract.py index 3d39eb5..dc401fd 100755 --- a/tools/extract.py +++ b/tools/extract.py @@ -33,8 +33,6 @@ attachment_query = ''' FROM attachment WHERE - id = ? - AND type = 'wiki' ORDER BY filename, time @@ -43,8 +41,14 @@ attachment_query = ''' def isotime(t): return None if t == 0 else time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(t)) -def hashname(whatever): - return hashlib.sha1(unicode(whatever)).hexdigest() +def attachment_link(row): + h = lambda whatever: hashlib.sha1(whatever.encode()).hexdigest() + h1 = h(row.id) + h2 = h(row.filename) + fn2 = os.path.splitext(row["filename"])[1] + return \ + os.path.join("attachments", "wiki", h1[:3], h1, h2 + fn2), \ + os.path.join(urllib.parse.quote(row.id, ""), urllib.parse.quote(row.filename, "")) with open("filter.json") as f: filter = json.load(f) @@ -73,4 +77,7 @@ for row in db.execute(wiki_query): with open("markdown/{}.md".format(slug), "w") as f: f.write(md) +for row in db.execute(attachment_query): + print("{} => {}".format(*attachment_link(row))) + db.close() -- cgit v1.2.3