Python geocoding The address of a LinkedIn user contact

Source: Internet
Author: User

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)]}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.