CODE:
#!/usr/bin/python #-*-Coding:utf-8-*-"Created on 2014-8-18@author:guaguastd@name:linkedin_connection_ retrieve.py ' # import loginfrom login import linkedin_login# import jsonimport jsonfrom prettytable import prettytable# A ccess to LinkedIn Apilinkedin_api = linkedin_login () connections = Linkedin_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 ()) # Print the Connections#print json.dumps (connections, indent=1) pt = prettytable (field_names=[' Name ', ' Location ']) Pt.align = ' L ' [Pt.add_row ((c[' firstName ' + ' + ' + c[' lastName '], c[' location ' [' name ']))))-for C in connections[' Values '] if C.has_key (' Location ')]print PT
RESULT:
+-------------------------+----------------------------+| Name | Location |+-------------------------+----------------------------+| Fly Yellow | Beijing city, China | | James Liao | San Francisco Bay Area | | Gerald Soparkar | San Francisco Bay Area | | Dimitrios Kouzis-loukas | Birmingham, Kingdom | | Xiaodong Xu | Beijing city, China | | Xinsong Li | China | | Tech Backyard | Chengdu, Sichuan, China | | Yan Super hu | Xingtai, Hebei, China | | Knox | Beijing city, China | | Zhang Jason | Beijing city, China | | Qu Sisyphus | States | | Honglin Zhang | Foshan, Guangdong, China | | Beyond Bzhou | States |+-------------------------+----------------------------+