-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfetch_connections.py
More file actions
executable file
·26 lines (21 loc) · 1011 Bytes
/
fetch_connections.py
File metadata and controls
executable file
·26 lines (21 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python
import requests, json, itertools, math, tqdm
import pymongo
with pymongo.MongoClient("localhost", 27017) as client:
db = client.get_database("github")
users = db.get_collection("users")
people = list(users.find({}, ["login", "followers_url", "following_url"]))
params = {
"access_token": "1d90e32a44098512ae8936772d8e38feeebb02da"
}
for person in tqdm.tqdm(people):
followers = requests.get(person["followers_url"], params=params).json()
following = requests.get(person["following_url"].rstrip("{/other_user}"), params=params).json()
connections = followers + following
connection_logins = set([each["login"] for each in connections])
users.update_one({ "login": person["login"] }, { "$set": { "connections": list(connection_logins) } })
for connection in connections:
try:
users.insert_one(connection)
except pymongo.errors.DuplicateKeyError:
pass