-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.py
More file actions
70 lines (51 loc) · 1.93 KB
/
API.py
File metadata and controls
70 lines (51 loc) · 1.93 KB
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
import json
from flask import Flask, jsonify, request
import logging
import logging.config
class MyApp(Flask):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.waypoints = {}
# Add any additional initialization code here
def telemetry(self):
# convert to dictionary to iterate
dictionary = json.loads(request.data)
print('\n')
for key in dictionary:
print(key, " : ", dictionary[key])
print('\n \n')
return "success"
def kraken(self):
# convert to dictionary to iterate
dictionary = json.loads(request.data)
print('\n')
for key in dictionary:
print(key, " : ", dictionary[key])
print('\n \n')
return "success"
def post_mission(self):
self.waypoints = json.loads(request.data)
return "mission uploaded to API"
def get_mission(self):
return jsonify(self.waypoints)
def fire_coords(self):
# convert to dictionary to iterate
dictionary = json.loads(request.data)
print('\n')
for key in dictionary:
print("\n\n---------------------FIRE TARGET COORDINATES ACQUIRED------------------------")
print(key, " : ", dictionary[key])
print('\n \n')
return "success"
app = MyApp(__name__)
# logging.getLogger('werkzeug').setLevel(logging.ERROR)
# logging.basicConfig(level=logging.WARNING)
# app.logger.setLevel(logging.CRITICAL)
# Define your routes
app.add_url_rule('/telemetry', view_func=app.telemetry, methods=['POST'])
app.add_url_rule('/kraken', view_func=app.kraken, methods=['POST'])
app.add_url_rule('/mission', view_func=app.post_mission, methods=['POST'])
app.add_url_rule('/mission', view_func=app.get_mission, methods=['GET'])
app.add_url_rule('/fire_coords', view_func=app.fire_coords, methods=['POST'])
if __name__ == '__main__':
app.run(host="0.0.0.0")