CODE:
#!/usr/bin/python #-*-Coding:utf-8-*-"Created on 2014-8-20@author:guaguastd@name:geocode_connection_bing.py" From geopy import geocodersimport Jsongeo_app_key = "G = geocoders. Bing (Geo_app_key) # access to LinkedIn apifrom login Import Linkedin_loginlinkedin_api = Linkedin_login () connections = Lin Kedin_api.get_connections () Connections_data = R ' E:\eclipse\LinkedIn\dfile\linkedin_connections.json ' # Write Connections into Disk Filef = open (Connections_data, ' W ') F.write (json.dumps (connections, indent=1)) F.close () # Read data From disk Fileconnections = json.loads (open (Connections_data). Read ()) transforms = [(' Greater ', ' "), (' area ', ')]result s = {}for c in connections[' values ']: If not c.has_key (' location '): Continue transformed_location = c[' location ' [' N Ame '] for transform in transforms:transformed_location = Transformed_location.replace (*transform) Geo = g.ge Ocode (transformed_location, exactly_one=false) if Geo = = []: Continue results.update ({c[' LocatIon ' [' Name ']: Geo}) Print Results#print json.dumps (results, indent=1)
RESULT:
{u ' states ': [Location (states 27m 0.0s N, 98 57m 0.0s W)], U ' Chengdu, Sichuan, China ': [Location (Chengdu, Sichuan, China 40m 0.0s N, 104 5m 0.0s E)], U ' Beijing city, China ': [Location (Beijing, Beijing, China 11 54m 0.0s N 6 23m 0.0s E)], U ' China ': [Location (China 33m 0.0s N, 103 59m 0.0s E)], u ' San Francisco Bay area ': [Location (CA, States 43m 0.0s N, 122 15m 0.0s W)], u ' Foshan, Guangdong, China ': [Location (Foshan, Guangdong, China) 2m 0.0s N, 113 6m 0.0s e)], U ' Xingtai, Hebei, China ': [Location (Xingtai, Hebei, the China PNS 4m 0.0s N, the (29m 0.0s) e)], U ' Birmingham, Unit Ed Kingdom ': [Location (Birmingham, England, Kingdom-29m 0.0s N, 1 55m 0.0s W), location (Birmingham, England, Uni Ted Kingdom 27m 0.0s N, 1 43m 0.0s W), location (Birmingham Airport, England, Kingdom, 27m 0.0s N, 1 44m 0.0s W ), location (Birmingham business Park, England, Kingdom 28m 0.0s N, 1 43m 0.0s W)]}