diff options
Diffstat (limited to 'tools/extract.py')
-rw-r--r-- | tools/extract.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tools/extract.py b/tools/extract.py new file mode 100644 index 0000000..d60de84 --- /dev/null +++ b/tools/extract.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 + +import fnmatch +import hashlib +import json +import sqlite3 +import time +import urllib.parse + +wiki_query = ''' + SELECT + name, + version, + time / 1000000 AS time, + text + FROM wiki + ORDER BY + name, version +''' + +attachment_query = ''' + SELECT + id, + filename, + size, + author, + description, + ipnr, + time / 1000000 AS createdtime + FROM + attachment + WHERE + id = ? + AND + type = 'wiki' + ORDER BY + filename, time +''' + +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() + +with open("filter.json") as f: + filter = json.load(f) + +def keep(name): + for k, v in filter: + assert k in "+-" + if fnmatch.fnmatch(name, v): + return k == "+" + return True + +db = sqlite3.connect("trac.db") +db.row_factory = sqlite3.Row + +for row in db.execute(wiki_query): + if keep(row["name"]): + print(urllib.parse.quote(row["name"], ""), row["version"]) + +db.close() |