-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmerge-fares-ndf
46 lines (39 loc) · 1.06 KB
/
merge-fares-ndf
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
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
import json
import os
from tqdm import tqdm
data = json.load(open('data/ndf.json'))
for key, row in tqdm(data.items()):
fil = 'data/fares/%s.json' % row['from']
new_row = [ row['adult'], row['restriction'] ]
new_entry = [
{
"prices": {
row['ticket']: new_row
},
"route": row['route']
}
]
if not os.path.exists(fil):
j = { row['to']: new_entry }
else:
j = json.load(open(fil))
if row['to'] in j:
for route in j[row['to']]:
if row['route'] == route['route']:
route['prices'][row['ticket']] = new_row
else:
j[row['to']] = new_entry
json.dump(j, open(fil, 'w'), separators=(',', ': '), indent=2, sort_keys=True)
# ndf file contents:
# { restriction, from, route, to, adult, ticket }
# a fares file contents:
# "TO": [
# {
# "prices": {
# ticket_type: [price, restriction],
# },
# "toc": toc,
# "route": route_code
# }
# ],