blob: 202422ed9ae27624ba8f11dcc5c1f82381f26056 (
plain)
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
|
import sys
import sqlite3
import os
import os.path
def main(dbname):
con = sqlite3.connect(dbname)
con.execute("CREATE TABLE IF NOT EXISTS rooms(id INTEGER PRIMARY KEY, json TEXT NOT NULL)")
con.commit()
for filename in os.listdir():
base, extension = os.path.splitext(filename)
if extension == '.json':
with open(filename, 'r') as f:
json = f.read()
print("Inserting room {0}".format(int(base)))
con.execute("INSERT OR REPLACE INTO rooms(id, json) VALUES(?, ?);",
(int(base), json))
con.commit()
con.close()
if __name__ == "__main__":
if len(sys.argv) != 2:
print('Usage: {0} <database name>'.format(sys.argv[0]))
else:
main(sys.argv[1])
|