MCPcopy Create free account
hub / github.com/Surfer-Org/Protocol / save_graph

Function save_graph

cookbook/python/knowledge-graph/app.py:46–73  ·  view source on GitHub ↗
(G)

Source from the content-addressed store, hash-verified

44 net.save_graph('graph_current.html')
45
46def save_graph(G):
47 timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
48
49 # Save final HTML with timestamp
50 net.save_graph(f'graph_{timestamp}.html')
51
52 # Save JSON
53 graph_data = {
54 "nodes": [
55 {
56 "id": node,
57 "label": G.nodes[node].get('label'),
58 "text": G.nodes[node].get('text')
59 } for node in G.nodes()
60 ],
61 "edges": [
62 {
63 "from": u,
64 "to": v,
65 "label": G.edges[u, v].get('label')
66 } for u, v in G.edges()
67 ]
68 }
69
70 with open(f'graph_{timestamp}.json', 'w') as f:
71 json.dump(graph_data, f, indent=2)
72
73 print(f"\nFinal graph saved as:\ngraph_{timestamp}.html\ngraph_{timestamp}.json")
74
75try:
76 for bookmark in data['data']['content']:

Callers 1

app.pyFile · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected