Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
dffa8c66
Commit
dffa8c66
authored
Dec 19, 2013
by
Chris Rossi
Committed by
Diana Huang
Jan 16, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LinkedIn API finally works.
parent
76b15eae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
10 deletions
+7
-10
lms/djangoapps/linkedin/management/commands/__init__.py
+6
-10
lms/djangoapps/linkedin/management/commands/findusers.py
+1
-0
No files found.
lms/djangoapps/linkedin/management/commands/__init__.py
View file @
dffa8c66
"""
Class for accessing LinkedIn's API.
"""
import
hashlib
import
json
import
urllib2
import
urlparse
...
...
@@ -95,19 +94,16 @@ class LinkedinAPI(object):
"You must log in to LinkedIn in order to use this script. "
"Please use the 'login' command to log in to LinkedIn."
)
def
md5
(
email
):
"Compute md5 hash for an email address."
md5hash
=
hashlib
.
md5
()
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
emails
=
list
(
emails
)
# realize generator since we traverse twice
queries
=
','
.
join
((
"email="
+
email
for
email
in
emails
))
url
=
"https://api.linkedin.com/v1/people::(
%
s):(id)"
%
queries
url
+=
"?oauth2_access_token=
%
s"
%
self
.
tokens
.
access_token
request
=
urllib2
.
Request
(
url
,
headers
=
{
'x-li-format'
:
'json'
})
try
:
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
:
self
.
http_error
(
error
,
"Unable to access People API"
)
return
(
True
for
email
in
emails
)
lms/djangoapps/linkedin/management/commands/findusers.py
View file @
dffa8c66
...
...
@@ -34,6 +34,7 @@ def get_call_limits():
Use 80 emails per API call and 1 call per second.
"""
return
-
1
,
80
,
1
now
=
timezone
.
now
()
.
astimezone
(
pytz
.
timezone
(
'US/Pacific'
))
lastfriday
=
now
while
lastfriday
.
weekday
()
!=
FRIDAY
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment