-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest_server.py
78 lines (61 loc) · 2.42 KB
/
rest_server.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import json
from flask import Flask, request
import variables
from flight_db import FlightDB
import utility
app = Flask(__name__)
flight_database = FlightDB(variables.db_username, variables.db_password, variables.db_host_rest_server,
variables.db_port, variables.database)
@app.route('/actual_flight_data', methods=['GET'])
def get_actual_flight_data():
if request.method == 'POST':
return json.dumps(flight_database.check_flight_dicts(utility.get_flight_information_dict()))
else:
return "NO OK"
@app.route('/max_range_of_flights', methods=['POST'])
def get_max_range_of_flights():
"""
get max Range of received flights since specific date from database
example for interval string: '2020-07-24 11:20:41'
"""
if request.method == 'POST':
interval = request.get_data().decode("utf-8")
utility.get_max_range(flight_database.get_flight_data(interval))
else:
return "NO OK"
@app.route('/count_of_flights', methods=['POST'])
def get_count_of_flights():
"""
get count of flights since specific date from database
example for interval string: '2020-07-24 11:20:41'
"""
if request.method == 'POST':
interval = request.get_data().decode("utf-8")
utility.get_count_of_flights(flight_database.get_flight_data(interval))
else:
return "NO OK"
@app.route('/actual_ship_data', methods=['POST'])
def ship_data_endpoint():
if request.method == 'POST':
# returns a hardcoded string, because AIS Receiver receives no data from my location
return json.dumps([{'ship_name': 'MSI TEST', 'lat': 52.502158, 'lon': 13.444523, 'speed': 8, 'ship_size': 15}])
else:
return "NO OK"
@app.route('/history_of_flight', methods=['POST'])
def view_do():
if request.method == 'POST':
flight_number = request.get_data().decode("utf-8")
all_coordinates = flight_database.get_all_coordinates_of_flight_number(flight_number)
return json.dumps(all_coordinates)
else:
return "NO OK"
@app.route('/history_of_ship', methods=['POST'])
def get_all_positions_of_ship_name():
if request.method == 'POST':
ship_name = request.get_data().decode("utf-8")
all_coordinates = flight_database.get_all_coordinates_of_ship_name(ship_name)
return json.dumps(all_coordinates)
else:
return "NO OK"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3000)