-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.py
More file actions
46 lines (35 loc) · 1.31 KB
/
api.py
File metadata and controls
46 lines (35 loc) · 1.31 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
from flask import Flask, render_template, request, jsonify, send_file
import worker
import random
class api:
app = Flask(__name__)
collector = worker.collector()
@app.route('/', methods=['GET'])
def index():
return render_template('dashboard.html')
@app.route('/index.css', methods=['GET'])
def index_css():
return send_file('./templates/index.css')
@app.route('/api', methods=['GET'])
def api():
return "501 Not Implemented" # TODO: implement historical data retrieval and filtering
@app.route('/api/latest', methods=['GET'])
def latest():
return jsonify(api.collector.reader.value_store)
@app.route('/api/weather', methods=['GET'])
def weather():
return jsonify(api.collector.reader.weather_data)
@app.route('/api/day', methods=['GET'])
def day():
return jsonify([random.random()*100 for _ in range(24)])
@app.route('/api/year', methods=['GET'])
def year():
return jsonify([random.random()*100 for _ in range(12)])
@app.route('/images/<path:path>', methods=['GET'])
def images(path):
if '..' in path:
return "403 Forbidden"
return send_file(f'./images/{path}.svg')
def run():
api.collector.start()
api.app.run(host='0.0.0.0')