git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
d6bb2a3
Branches
Tags
develop-client_server
master
typescript
fs-words.git
tools
convert.py
moved to flat files
Christian Fraß
commited
d6bb2a3
at 2017-04-17 17:05:04
convert.py
Blame
History
Raw
#!/usr/bin/env python3 import sys as _sys import os as _os import sqlite3 as _sqlite3 import json as _json def main(args): path = _os.path.join("queries", "convert.sql.tpl") handle = open(path, "r") querytemplate = handle.read() handle.close() arguments = {} connection = _sqlite3.connect(_os.path.join("db", "words.sqlite")) result = connection.cursor().execute(querytemplate, arguments).fetchall() connection.close() for index in range(len(result)): line = result[index] if True: id_ = line[0] if True: type_ = line[1] if True: description = line[2] if True: tags = ([] if (line[3] is None) else line[3].split("|")) if True: translations = {} pairs = list(map(lambda x: tuple(x.split(":", 2)), line[4].split("|"))) for (language , lemma) in sorted(pairs, key = lambda pair: pair[0]): if (language not in translations): translations[language] = [] translations[language].append(lemma) obj = { "type": type_, "description": description, "tags": tags, "translations": translations, } name = ("concept_%u.json" % (id_)) path = _os.path.join("concepts", name) output = _json.dumps(obj, indent = "\t", ensure_ascii = False) handle = open(path, "w") handle.write(output) handle.close() main(_sys.argv[1:])