Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 51 lines (33 sloc) 1.104 kb
f492412 @micahwalter added script to generate sqlite db from json
authored
1 #!/usr/bin/env python
2
3 import sys
4 import json
5 import os
6 import os.path
7 import types
8 import utils
9 import sqlite3 as lite
10
11 import logging
12 logging.basicConfig(level=logging.INFO)
13
14 if __name__ == '__main__':
15
16 whoami = os.path.abspath(sys.argv[0])
17
18 bindir = os.path.dirname(whoami)
19 rootdir = os.path.dirname(bindir)
20
21 datadir = os.path.join(rootdir, 'objects')
22 metadir = os.path.join(rootdir, 'meta')
23
24 outfile = os.path.join(metadir, 'objects.sqlite3')
25
26 con = None
27
28 con = lite.connect(outfile)
29
30 with con:
31
32 cur = con.cursor()
33 cur.execute("DROP TABLE IF EXISTS objects")
34 cur.execute("CREATE TABLE objects(id INT, description TEXT, url text)")
35
36 for root, dirs, files in os.walk(datadir):
37 for f in files:
38 path = os.path.join(root, f)
39 logging.info("processing %s" % path)
40
41 data = json.load(open(path, 'r'))
42
43 object_id = data.get('id', [])
44 description = data.get('description', [])
45 url = data.get('url', [])
46
47 cur.execute("INSERT INTO objects VALUES(?,?,?)" , (object_id, description, url))
48
49
50
51 logging.info("done");
Something went wrong with that request. Please try again.