Python 摘录LinkedIn用户联系人

CODE:

#!/usr/bin/python 
# -*- coding: utf-8 -*-

'''
Created on 2014-8-18
@author: guaguastd
@name: linkedin_connection_retrieve.py
'''

# import login
from login import linkedin_login

# import json
import json
from prettytable import PrettyTable

# access to linkedin api
linkedin_api = linkedin_login()

connections = linkedin_api.get_connections()
connections_data = r'E:eclipseLinkedIndfilelinkedin_connections.json'

# Write connections into disk file
f = open(connections_data, 'w')
f.write(json.dumps(connections, indent=1))
f.close()

# Read data from disk file
connections = 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                   |
+-------------------------+----------------------------+
| 飞 黄                   | Beijing City, China        |
| James Liao              | San Francisco Bay Area     |
| Gerald Soparkar         | San Francisco Bay Area     |
| Dimitrios Kouzis-Loukas | Birmingham, United Kingdom |
| Xiaodong Xu             | Beijing City, China        |
| Xinsong Li              | China                      |
| 科技 后院               | Chengdu, Sichuan, China    |
| 彦超 胡                 | Xingtai, Hebei, China      |
| 诺克 埃                 | Beijing City, China        |
| Zhang Jason             | Beijing City, China        |
| qu Sisyphus             | United States              |
| 洪林 张                 | Foshan, Guangdong, China   |
| beyond Bzhou            | United States              |
+-------------------------+----------------------------+


原文地址:https://www.cnblogs.com/blfshiye/p/4660505.html