-
Notifications
You must be signed in to change notification settings - Fork 0
/
maketbl.py
35 lines (30 loc) · 1003 Bytes
/
maketbl.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
import glob, json
from datetime import datetime
import dataset
LAYERS = {
'0': 'Active EL Licenses',
'1': 'Active ML Licenses',
'2': 'Active LL Licenses',
'3': 'Active RL Licenses',
'4': 'Application EL Licenses',
'5': 'Application ML Licenses',
'6': 'Application LL Licenses',
'7': 'Application RL Licenses'
}
e = dataset.connect('sqlite://')
tbl = e['licenses']
for id, name in LAYERS.items():
with open('data/ug_%s.json' % id, 'r') as fh:
data = json.load(fh)
for f in data.get('features'):
a = f.get('attributes')
for k, v in a.items():
if k.startswith('Dte') and v is not None:
dt = datetime.fromtimestamp(int(v)/1000)
a[k] = dt.isoformat()
a['LayerName'] = name
a['LayerID'] = id
print a, name
tbl.insert(a)
#print data.get('features'), name
dataset.freeze(tbl, filename="licenses_ug.csv", format='csv')