-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
59 lines (47 loc) · 1.76 KB
/
app.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
import os
from flask import Flask, render_template, jsonify
import requests
import json
url = "http://flaskosa.herokuapp.com/cmd/"
headers = {
'content-type': "application/json",
'x-apikey': "560bd47058e7ab1b2648f4e7",
'cache-control': "no-cache"
}
app = Flask(__name__)
# initial page
@app.route('/')
def hello_world():
title = "OSA"
name = "Welcome to cloud OSA!"
return render_template('index.html', title=title, name=name)
# the following 3 routes are used for the live graph
@app.route('/api/start')
def start():
res = requests.request("GET", url + 'START', headers=headers)
return "started..."
@app.route('/api/stop')
def stop():
res = requests.request("GET", url + 'STOP', headers=headers)
return "stopped..."
@app.route('/api/trace')
def trace():
res = requests.request("GET", url + 'TRACE', headers=headers).json()
print(len(res['xdata']))
return jsonify(res)
# the routes below are used for the query portion on the bottom half of the page
# they can also be accessed by directly visiting localhost:8080/api/cmd or another desired route
@app.route('/api/cmd')
def cmd():
return requests.request("GET", "http://flaskosa.herokuapp.com/cmd", headers=headers).text
@app.route('/api/cmd/<section>')
def query(section):
return requests.request("GET", url + section.upper(), headers=headers).text
@app.route('/api/cmd/ECHO/<section>')
def echo(section):
return requests.request("GET", url + "ECHO/" + section, headers=headers).text
@app.route('/api/cmd/LIM/<s1>/<s2>')
def limset(s1, s2):
return requests.request("GET", url + "LIM/[%s,%s]"%(s1, s2), headers=headers).text
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)