[Cryptech-Commits] [wiki] 28/75: Calculate attachment links
git at cryptech.is
git at cryptech.is
Fri Oct 8 18:51:54 UTC 2021
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch production
in repository wiki.
commit ad1cc0517983e599897929b4c94463bf2af78f7c
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Sun Feb 14 05:49:45 2021 +0000
Calculate attachment links
Not using these yet
---
tools/extract.py | 15 +++++++++++----
1 file 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()
More information about the Commits
mailing list