forked from madewulf/MigrationsMap.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worldBankDataGetter.py
72 lines (59 loc) · 2.12 KB
/
worldBankDataGetter.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from parser import load_matrices
import requests
import json
def getGDP():
matrix, reversed_matrix, code_to_name = load_matrices()
f = open("GDP.json","w")
res ={}
for code in code_to_name:
r = requests.get("http://api.worldbank.org/countries/%s/indicators/NY.GDP.PCAP.CD?per_page=10&date=2007:2007&format=json" % code)
print r.content
try :
print code
content=json.loads(r.content)
res[code]= content[1][0]["value"]
print res[code]
except Exception, e:
print e
#print res[code]
f.write(json.dumps(res))
f.close()
#getGDP()
def getPop():
matrix, reversed_matrix, code_to_name = load_matrices()
f = open("POP.json","w")
res ={}
for code in code_to_name:
r = requests.get("http://api.worldbank.org/countries/%s/indicators/SP.POP.TOTL?per_page=10&date=2007:2007&format=json" % code)
print r.content
try :
print code
content=json.loads(r.content)
res[code]= content[1][0]["value"]
print res[code]
except Exception, e:
print e
#print res[code]
f.write(json.dumps(res))
f.close()
def getIndicator(indicator_code, file_name):
matrix, reversed_matrix, code_to_name = load_matrices()
f = open(file_name+".json","w")
res ={}
for country_code in code_to_name:
print "http://api.worldbank.org/countries/%s/indicators/%s?per_page=10&date=2007:2007&format=json" % (country_code,indicator_code)
r = requests.get("http://api.worldbank.org/countries/%s/indicators/%s?per_page=10&date=2007:2007&format=json" % (country_code,indicator_code))
print r.content
try :
print country_code
content=json.loads(r.content)
res[country_code]= content[1][0]["value"]
print res[country_code]
except Exception, e:
print e
#print res[code]
f.write(json.dumps(res))
f.close()
#getIndicator("SH.TBS.INCD","TUBERCULOSIS")
#getIndicator("SH.DYN.AIDS.ZS","HIV")
getIndicator("SH.DYN.MORT","UNDER-FIVE-MORTALITY")