git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
9785e31
Branches
Tags
develop-client_server
master
typescript
fs-words.git
scripts
helpers.py
query scripts
Christian Fraß
commited
9785e31
at 2017-03-19 21:20:53
helpers.py
Blame
History
Raw
#!/usr/bin/env python3 import os as _os import sqlite3 as _sqlite3 import json as _json def pattern(content): return ("%%%s%%" % content) def transform(entries, names): # return entries return list(map(lambda entry: dict(zip(names, entry)), entries)) def query(name, arguments = {}): path = _os.path.join("queries", "%s.sql.tpl" % name) handle = open(path, "r") querytemplate = handle.read() handle.close() connection = _sqlite3.connect(_os.path.join("db", "words.sqlite")) result = connection.cursor().execute(querytemplate, arguments).fetchall() connection.close() return result def macro(query_name, query_arguments, transform_names): print(_json.dumps(transform(query(query_name, query_arguments), transform_names), indent = "\t"))