-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.py
33 lines (23 loc) · 936 Bytes
/
map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
from flask import Flask, render_template, request, jsonify, redirect, url_for
from netstat import netstat
app = Flask(__name__)
@app.route('/')
def index():
return redirect(url_for('map'))
# return "<a href=\"/map\">Map is here</a>"
@app.route('/map')
def map():
my_loc = netstat.get_my_location()
my_lat, my_lon = my_loc['lat'], my_loc['lon']
my_desc = f"{my_loc['city']}, {my_loc['region']}. {my_loc['country']}"
return render_template("map.html.j2", my_lat=my_lat, my_lon=my_lon, my_desc=my_desc)
@app.route('/map/update', methods=["POST"])
def update():
client_procs = request.get_json(force=True)
app.logger.info(f"Client has layers: {client_procs}")
new_markers, new_procs = netstat.run(known_procs=client_procs)
app.logger.info(f"Sending layers: {new_procs}")
return jsonify([new_markers, new_procs])
if __name__ == '__main__':
app.run(debug=True)