-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
60 lines (37 loc) · 1.36 KB
/
run.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
import datetime
import logging
import goodwee_provider
from db.db_prov import get_inverter_log_last_log, get_inverter_log_last_log_limit
logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
level=logging.INFO,
datefmt='%Y-%m-%d %H:%M:%S')
print(f"LOGGING LEVEL: {logging.getLevelName(logging.getLogger().getEffectiveLevel())}")
import os
log = logging.getLogger(__name__)
from flask import Flask, jsonify, render_template
base_prefix = "/api"
app = Flask(__name__, static_url_path='/static', template_folder='templates', static_folder='static')
# Api Feeds for clients
# app.register_blueprint(api_content, url_prefix=base_prefix)
@app.route("/hello")
def hello():
return "hello"
@app.route("/")
def status():
data = get_inverter_log_last_log()
current_time = datetime.datetime.now().strftime("%H:%M:%S")
data["current_time"] = data["t"]
return render_template("main.html", data=data)
@app.route("/json")
def status_json():
data = get_inverter_log_last_log()
current_time = datetime.datetime.now().strftime("%H:%M:%S")
data["current_time"] = data["t"]
return jsonify(data), 200
@app.route("/json200")
def status_json200():
data = get_inverter_log_last_log_limit(5000)
data = [{"x": row["t"], "y": row["house_consumption"]} for row in data]
serie = {"serie": data}
return jsonify(serie), 200