Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
from geojsontosvg import transform_to_json
from parser import load_matrices
from collections import OrderedDict
import json
res = transform_to_json()
matrix, reversed_matrix,csv_code_to_name = load_matrices()

from_csv = csv_code_to_name.values()
from_json = res.keys()

#print len(from_csv),from_csv
from_csv = [unicode(name,errors='ignore') for name in from_csv]

unmapped_csv_stats = sorted(list(set(from_csv) - set(from_json)))

csv_name_to_code=OrderedDict()
for code in csv_code_to_name:
    csv_name_to_code[unicode(csv_code_to_name[code],errors="ignore")]=code
print "name_to_code keys", sorted(csv_name_to_code.keys())
json_names = sorted(from_json)
import sys
#line = sys.stdin.readline()
res = OrderedDict()
entered_letter = ""
while unmapped_csv_stats:
    unmapped_stat = unmapped_csv_stats[0]
    print "Match for :", unmapped_stat , ("or beginning letter")
    i=1
    print "0 : not found"
    if entered_letter !="":
        show_list= filter(lambda x:x.lower().startswith(entered_letter),json_names)
Ejemplo n.º 5
0
        except Exception, e:
            print e
            x1 = middle_point[0]
            y1 = middle_point[1]-d/d_div
        svg_path = "M %s %s" %(lolatoxy(from_point)) + " Q %s %s "% (x1,y1) +"%s %s" %(lolatoxy(point))
        #print svg_path
        res[code]=(svg_path,name, migration)
    f = open('generated/'+file_prefix+country_code+".json","w")
    print '/generated/'+file_prefix+country_code+".json"
    f.write(json.dumps(res))
    f.close()


geoloc_data = json.loads(open('geoloc.json').read())

matrix, reversed_matrix,code_to_name = load_matrices()
wrong = []
ccode_to_coordinates = {}
for code in geoloc_data :
    try:
        ccode_to_coordinates[code]=geoloc_data[code]['results'][0]['geometry']['location']
    except Exception,e :
        wrong.append(code)
        print "wrong", wrong


for country_code in matrix :
    create_country_json(country_code,matrix,ccode_to_coordinates)
    create_country_json(country_code,reversed_matrix,ccode_to_coordinates,"out")

f = open("code_to_coordinates.json",'w')