summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2021-02-14 05:49:45 +0000
committerRob Austein <sra@hactrn.net>2021-02-14 05:53:54 +0000
commitad1cc0517983e599897929b4c94463bf2af78f7c (patch)
treeda60c73863c5fec24f8273381c11143b2286ec3c
parent8e59cfff8f67a0c22d11f988afb3d95fa8530174 (diff)
Calculate attachment links
Not using these yet
-rwxr-xr-xtools/extract.py15
1 files changed, 11 insertions, 4 deletions
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()