summaryrefslogtreecommitdiff
path: root/src/todb.py
diff options
context:
space:
mode:
authorJeff Armstrong <jeff@approximatrix.com>2013-07-24 15:26:57 -0400
committerJeff Armstrong <jeff@approximatrix.com>2013-07-24 15:26:57 -0400
commitca7982703591629ff73a8617e72c9496e9e92ab5 (patch)
treeeebd5e528318b478c894cb171312412de55bacec /src/todb.py
parente3ebcb1ad2f1e7ca946a820c49b7e78e07d5cd8c (diff)
downloadpyohio2013-ca7982703591629ff73a8617e72c9496e9e92ab5.tar.gz
pyohio2013-ca7982703591629ff73a8617e72c9496e9e92ab5.zip
Initial skeleton uploaded.
Diffstat (limited to 'src/todb.py')
-rw-r--r--src/todb.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/todb.py b/src/todb.py
new file mode 100644
index 0000000..202422e
--- /dev/null
+++ b/src/todb.py
@@ -0,0 +1,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]) \ No newline at end of file