4
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2025-07-03 09:37:45 +00:00

Merge branch 'future'

This commit is contained in:
Arceliar
2021-07-06 19:12:14 -05:00
4 changed files with 311 additions and 92 deletions

View File

@ -1,11 +1,10 @@
#!/usr/bin/env python
from flask import Config
from database import NodeDB
import graphPlotter
import cgi
import urllib, json
url = "http://y.yakamo.org:3000/current"
#url = "http://y.yakamo.org:3000/current"
url = "current"
# nodes indexed by coords
class NodeInfo:
@ -34,9 +33,18 @@ def generate_graph(time_limit=60*60*3):
data = json.loads(response.read())["yggnodes"]
toAdd = []
for ip in data:
info = NodeInfo(ip, data[ip][0])
if len(data[ip]) >= 3: info.label = data[ip][2]
for key in data:
if 'address' not in data[key] or 'coords' not in data[key]: continue
ip = data[key]['address']
coords = data[key]['coords']
info = NodeInfo(ip, coords)
try:
if 'nodeinfo' in data[key]:
if 'name' in data[key]['nodeinfo']:
label = str(data[key]['nodeinfo']['name'])
if len(label) <= 32:
info.label = label
except: pass
info.label = cgi.escape(info.label)
toAdd.append(info)
@ -67,16 +75,5 @@ def generate_graph(time_limit=60*60*3):
with open('static/graph.json', 'w') as f:
f.write(js)
def load_graph_from_db(time_limit):
config = Config('./')
config.from_pyfile('web_config.cfg')
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__':
generate_graph()