def fetch_coutries_coords(file_path, sheet_name): gdp_data = xlrd.open_workbook(file_path) table = gdp_data.sheet_by_name(sheet_name) nrows = table.nrows countries_coords = {} for rownum in range(1, nrows): country_name = table.cell(rownum, 2).value print('Quering %s coord...' % country_name) coord = geocode.address_to_coords(country_name) countries_coords[country_name] = coord print 'done.' return countries_coords
def add_coords(data): data = filter(lambda x: type(x) is dict, data) new = [] for x in xrange(len(data)): print('processing %s out of %s' % (x, len(data))) coords = geocode.address_to_coords(data[x]['actor_attributes_location']) if coords is not None: coords = GeoCoord(coords['lat'], coords['lng']) data[x]['coords'] = coords del data[x]['actor_attributes_location'] new.append(data[x]) return new