Commit dffa8c66 by Chris Rossi Committed by Diana Huang

LinkedIn API finally works.

parent 76b15eae
""" """
Class for accessing LinkedIn's API. Class for accessing LinkedIn's API.
""" """
import hashlib
import json import json
import urllib2 import urllib2
import urlparse import urlparse
...@@ -95,19 +94,16 @@ class LinkedinAPI(object): ...@@ -95,19 +94,16 @@ class LinkedinAPI(object):
"You must log in to LinkedIn in order to use this script. " "You must log in to LinkedIn in order to use this script. "
"Please use the 'login' command to log in to LinkedIn.") "Please use the 'login' command to log in to LinkedIn.")
def md5(email): emails = list(emails) # realize generator since we traverse twice
"Compute md5 hash for an email address." queries = ','.join(("email=" + email for email in emails))
md5hash = hashlib.md5() url = "https://api.linkedin.com/v1/people::(%s):(id)" % queries
md5hash.update(email)
return md5hash.hexdigest()
hashes = ','.join(("email-hash=" + md5(email) for email in emails))
url = "https://api.linkedin.com/v1/people::(%s):(id)" % hashes
url += "?oauth2_access_token=%s" % self.tokens.access_token url += "?oauth2_access_token=%s" % self.tokens.access_token
request = urllib2.Request(url, headers={'x-li-format': 'json'}) request = urllib2.Request(url, headers={'x-li-format': 'json'})
try: try:
response = urllib2.urlopen(request).read() response = urllib2.urlopen(request).read()
print "GOT IT!", response values = json.loads(response)['values']
accounts = set(value['_key'][6:] for value in values)
return (email in accounts for email in emails)
except urllib2.HTTPError, error: except urllib2.HTTPError, error:
self.http_error(error, "Unable to access People API") self.http_error(error, "Unable to access People API")
return (True for email in emails) return (True for email in emails)
...@@ -34,6 +34,7 @@ def get_call_limits(): ...@@ -34,6 +34,7 @@ def get_call_limits():
Use 80 emails per API call and 1 call per second. Use 80 emails per API call and 1 call per second.
""" """
return -1, 80, 1
now = timezone.now().astimezone(pytz.timezone('US/Pacific')) now = timezone.now().astimezone(pytz.timezone('US/Pacific'))
lastfriday = now lastfriday = now
while lastfriday.weekday() != FRIDAY: while lastfriday.weekday() != FRIDAY:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment