-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.py
38 lines (25 loc) · 873 Bytes
/
export.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sqlite3
import sys
import codecs
def verify(conn):
result = conn.execute("SELECT value FROM info WHERE key = 'schema_version'")
version = int(result.fetchone()[0])
assert version == 9
def write_file(filename, data):
with codecs.open(filename, 'w', 'utf8') as f:
f.writelines(data)
def dump_units(conn):
result = conn.execute("SELECT title FROM units")
return (u"{0}\n".format(row[0]) for row in result)
def dump_abstract_units(conn):
result = conn.execute("SELECT title FROM abstract_units")
return (u"{0}\n".format(row[0]) for row in result)
def main(path):
print(path)
conn = sqlite3.connect(path)
verify(conn)
write_file('units.txt', dump_units(conn))
write_file('abstract_units.txt', dump_abstract_units(conn))
if __name__ == '__main__':
assert len(sys.argv) > 1
main(sys.argv[1])