-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (58 loc) · 1.78 KB
/
Copy pathmain.py
File metadata and controls
76 lines (58 loc) · 1.78 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sqlite3
import networkx
import json
from pyvis.network import Network
def main():
connection = sqlite3.connect("zigistry.db")
cursor = connection.cursor()
cursor.execute("SELECT repo_id, dependent FROM repo_dependents")
repo2repo_connection = cursor.fetchall()
graph_builder = networkx.DiGraph()
for repo_1, repo_2 in repo2repo_connection:
graph_builder.add_edge(repo_2, repo_1)
print(graph_builder)
graph_data = {"nodes": [], "edges": []}
for node in graph_builder.nodes():
graph_data["nodes"].append(
{
"id": node,
"label": str(node),
}
)
for source, target in graph_builder.edges():
graph_data["edges"].append({"from": source, "to": target})
with open("./graph.json", "w", encoding="utf-8") as json_file:
json.dump(graph_data, json_file, indent=0)
net = Network(
width="100%",
height="90vh",
bgcolor="#1e1e1e",
font_color="white",
directed=True,
# I am adding this because it was unnesecarily generating lib/ folder.
cdn_resources="remote",
)
net.from_nx(graph_builder)
net.add_node(
"zigister",
shape="image",
image="zigister-finds-repos.svg",
size=200,
x=100,
y=0,
fixed=False,
mass=5,
)
net.force_atlas_2based()
net.options.physics.stabilization = False
net.write_html("graph.html")
with open("graph.html", "r+") as file:
content = file.read()
file.seek(0)
file.write(
content.replace(
"</style>", "#loadingBar{display:none!important}\nhtml, body {padding:0; margin:0;}</style>", 1
)
)
if __name__ == "__main__":
main()