aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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()