import json import algorithms import store from lib import run_server, get, post, read_html nodes = None grid = None @get('/') def index(): global nodes global grid nodes, grid = store.extract_osm_nodes("university.osm") return read_html('templates/index.html') @post('/shortest-path') def shortest_path(body): body = json.loads(body) source_id = algorithms.get_closest_node_id(nodes, store.Node(-1, body['lat1'], body['lng1'])) target_id = algorithms.get_closest_node_id(nodes, store.Node(-1, body['lat2'], body['lng2'])) path = algorithms.find_shortest_path(nodes, source_id, target_id) print(path) response = {"path": [(nodes[node].lat, nodes[node].lng) for node in path]} return json.dumps(response) run_server()