forked from italia/public-opendata-sources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_orgs.py
executable file
·29 lines (21 loc) · 888 Bytes
/
export_orgs.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
import sys, json
from urllib.request import urlopen
from collections import OrderedDict
list_host = 'http://localhost:5000'
list_url = list_host + '/api/3/action/organization_list'
get_url = list_host + '/api/3/action/organization_show'
contents = urlopen(list_url)
org_list = json.load(contents)['result']
for org_name in org_list:
org_url = get_url + "?id=" + org_name
print("=== Loading " +org_name + " from " + org_url)
org_content = urlopen(org_url)
org_obj = json.load(org_content)['result']
org = OrderedDict()
for key in ('name', 'title', 'description', 'site', 'email', 'region', 'identifier'):
if key in org_obj and org_obj[key]:
org[key] = org_obj[key]
org_filename = "orgs/"+org_name+".json"
with open(org_filename,"w+") as f:
f.write(json.dumps(org, indent=4))
print("=== Saved in "+org_filename+"\n")