-
Notifications
You must be signed in to change notification settings - Fork 2
/
world_bank_script.py
48 lines (34 loc) · 1.52 KB
/
world_bank_script.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
import json
import os
import numpy as np
import pandas as pd
import requests as req
print("Welcome to my simple script which calls for net official development assistance statistic for a country.")
print("Putting together country list....")
request_countries = req.get('http://api.worldbank.org/v2/countries?format=json').json()
country_list = []
country_info = {}
iso_codes = []
name = []
for i in range(1, 7):
request_country_iso = req.get("http://api.worldbank.org/v2/countries?format=json&page=%s" %(i)).json()
country_list.append(request_country_iso)
for i in range(len(country_list)):
for j in range(0, 49):
iso_codes.append(country_list[i][1][j]['iso2Code'])
name.append(country_list[i][1][j]['name'])
query = input("Do you want to see a list of available countries? (y/n) ")
if query == "y":
for i in range(len(country_list)):
for j in range(0, 49):
print(country_list[i][1][j]['name'])
country_info = dict(zip(name, iso_codes))
country = input("What country are you looking for? ")
#def wb_find_data(country):
for name, iso_codes in country_info.items():
if country == name:
ref = iso_codes
request = req.get("http://api.worldbank.org/v2/countries/%s/indicators/DT.ODA.ODAT.CD?format=json" %(ref)).json()
for i in range(0, 6):
print("In " + str(request[1][i]['date']) + ", " + str(country) + " had " + str(request[1][i]['value']) + " in net official development assistance received (Current US$).")
#print(request[1][i]['value'])