-
Notifications
You must be signed in to change notification settings - Fork 15
/
json2sqlite.py
executable file
·31 lines (24 loc) · 1.16 KB
/
json2sqlite.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
#!/usr/bin/env python
from losspager.schema import emailschema
import sys
import argparse
if __name__ == '__main__':
desc = 'Export PAGER users, regions, events, etc. from JSON file into Sqlite database.'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('jsonfile', help='Specify input JSON file name')
parser.add_argument('dbfile', help='Specify output sqlite DB file name')
parser.add_argument('-n', '--num-users', type=int, default=None,
help='Specify number of users to export')
args = parser.parse_args()
tmpfile = 'anonymized_pager_users.db'
fileurl = 'sqlite:///%s' % args.dbfile
jsonfile = 'pager_profiles.json'
session = emailschema.create_db(fileurl, args.jsonfile, nusers=args.num_users, create_db=True)
nusers = session.query(emailschema.User).count()
print('There are %i users in this new database.' % nusers)
session.close()
# do a quick test of the new database that we created...
session = emailschema.get_session(fileurl)
nusers = session.query(emailschema.User).count()
print('There are %i users in this new database.' % nusers)
sys.exit(0)