5
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2024-11-25 18:11:36 +00:00
yggdrasil-map/web/updateGraph.py

30 lines
721 B
Python
Raw Normal View History

#!/usr/bin/env python
from flask import Config
from database import NodeDB
import graphPlotter
def generate_graph(time_limit=60*60*3):
2015-11-21 11:47:21 +00:00
nodes, edges = load_graph_from_db(time_limit)
print '%d nodes, %d edges' % (len(nodes), len(edges))
2015-11-21 11:47:21 +00:00
graph = graphPlotter.position_nodes(nodes, edges)
json = graphPlotter.get_graph_json(graph)
2015-11-21 11:47:21 +00:00
with open('static/graph.json', 'w') as f:
f.write(json)
def load_graph_from_db(time_limit):
2015-11-21 11:47:21 +00:00
config = Config('./')
config.from_pyfile('web_config.cfg')
2015-11-21 11:47:21 +00:00
with NodeDB(config) as db:
nodes = db.get_nodes(time_limit)
edges = db.get_edges(nodes, 60*60*24*7)
return (nodes, edges)
if __name__ == '__main__':
2015-11-21 11:47:21 +00:00
generate_graph()