| 44 | net.save_graph('graph_current.html') |
| 45 | |
| 46 | def 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 | |
| 75 | try: |
| 76 | for bookmark in data['data']['content']: |