forked from 7h0ma5/vatradar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
38 lines (30 loc) · 1020 Bytes
/
web.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
34
35
36
37
38
from bottle import route, run, request, abort, static_file
from pymongo import Connection
from bson import json_util
import bottle
import json
def jdumps(obj):
return json.dumps(obj, default=json_util.default)
connection = Connection("localhost", 27017)
db = connection.vatradar
@route("/")
def index():
return static_file("index.html", root="web/")
@route("/static/<filename:path>")
def index(filename):
return static_file(filename, root="web/")
@route("/pilots/", method="GET")
def get_pilots():
pilots = db.pilots.find({}, {"callsign": 1, "position": 1, "heading": 1, "speed": 1, "aircraft": 1})
return jdumps([pilot for pilot in pilots])
@route("/pilots/:id", method="GET")
def get_pilot(id):
pilot = db.pilots.find_one({"callsign": id})
if not pilot:
abort(404, 'No pilot with callsign %s' % id)
return jdumps(pilot)
@route("/atc/", method="GET")
def get_atc():
atc = db.atc.find({})
return jdumps([a for a in atc])
run(host='0.0.0.0', port=8080, debug=True)