-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathckfiumi_import.py
More file actions
executable file
·31 lines (27 loc) · 964 Bytes
/
ckfiumi_import.py
File metadata and controls
executable file
·31 lines (27 loc) · 964 Bytes
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
#!/usr/bin/env python
# -*- coding: utf8 -*-
# Hard codes
tomerge = {"Pescia di calamecca ":"Pescia",
"Pescia di pescia":"Pescia",
"Adda sup.":"Adda",
"Adda inferiore":"Adda",
}
# end of hard codes
import json
rivers = {}
for route in json.load(open('ckfiumi.json','r')):
river_name = route['river_name']
if river_name in tomerge:
river_name = tomerge[river_name]
if river_name in rivers:
rivers[river_name].append(route)
else:
rivers[river_name] = [route]
import pymongo
col = pymongo.MongoClient().wwsupdb.ckfiumi
for river_name,routes in rivers.iteritems():
routes.sort(key=lambda route:route['order'])
regions = list(set(map(lambda r:r['region'],routes)))
provinces = list(set(filter(lambda p:p!=None,map(lambda r:r.get('province'),routes))))
river = {"_id":river_name,"regions":regions,"provinces":provinces,"routes_ckfiumi":routes}
col.insert(river)