-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild_graphfile.py
More file actions
executable file
·27 lines (20 loc) · 979 Bytes
/
build_graphfile.py
File metadata and controls
executable file
·27 lines (20 loc) · 979 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
27
#!/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")
users.fin
connections = list(users.find(projection=["login", "connections", "repos"]))
nodes = list()
login_to_group = dict()
for i, connection in enumerate(connections):
login_to_group[connection["login"]] = i
nodes.append({ "group": i, "login": connection["login"], "connections": connection.get("connections", []), "weight": len(repos) })
links = list()
for source in connections:
if "connections" in source:
for target in source.get("connections", []):
links.append({ "source": login_to_group[source["login"]], "target": login_to_group[target], "weight": 1 })
with open("graphFile.json", "w") as f:
json.dump({ "nodes": nodes, "links": links }, f)