diff options
| author | root <root@turin.home> | 2022-02-03 18:08:28 +0000 |
|---|---|---|
| committer | root <root@turin.home> | 2022-02-03 18:08:28 +0000 |
| commit | 1ca19f43c131d77f18008dde867e76153288de38 (patch) | |
| tree | 9423f24da815fee682b73189f03d18641c557b3e | |
| parent | 333bdb9507ca82709d92fe8919a9b40fc02d7dc7 (diff) | |
Exports and formatting. Reformatting.
| -rw-r--r-- | api.py | 2 | ||||
| -rw-r--r-- | dates.py | 4 | ||||
| -rw-r--r-- | heating.py | 9 | ||||
| -rw-r--r-- | main.py | 18 | ||||
| -rw-r--r-- | templates/export_choice.html | 8 | ||||
| -rw-r--r-- | weather.py | 1 |
6 files changed, 27 insertions, 15 deletions
@@ -1,6 +1,7 @@ from __main__ import app from __main__ import boiler + @app.route("/api/info") def api_info(): msg = """ @@ -22,6 +23,7 @@ def api_info(): """ return msg + @app.route("/api/current_temperature") def api_current_temperature(): return str(boiler.temperature) @@ -1,7 +1,7 @@ import time from datetime import datetime - +# https://www.w3schools.com/python/python_datetime.asp class date: def __init__(self): pass @@ -14,5 +14,3 @@ class date: def date(self): return int(datetime.now().strftime("%A")) - - @@ -34,11 +34,16 @@ class heating(ABC): self.turn_off() self.db.exec( "insert into temperature values (?,?,?,?)", - (self.date.day(), self.date.time(), self.temperature, self.target) + ( + self.date.day(), + self.date.time(), + self.temperature, + self.target, + ), ) self.db.exec( "insert into history values (?,?,?)", - (self.date.day(), self.date.time(), int(self.on)) + (self.date.day(), self.date.time(), int(self.on)), ) """ @@ -35,14 +35,15 @@ else: # Import API Script after Flask app and boiler classexists import api + def main_page(): # paramaterised location of template in 'templates' folder return render_template( "main.html", # Rounding value for user interface so number is not too long - actual_temp=round(boiler.temperature,2), + actual_temp=round(boiler.temperature, 2), target_temp=boiler.target, - forecast_temp=weather.temperature() + forecast_temp=weather.temperature(), ) @@ -72,18 +73,23 @@ def export_choice(): @app.route("/export/<opt>") def export(opt): - if opt == "txt": - pass - elif opt == "pdf": - pass + # Defensive handling of input + if opt in ["temperature", "weather", "history", "schedule"]: + data = db.exec("select * from {}".format(opt)) + o = "" + for i in data: + o += str(a) + "\n" + return o else: return render_template( "error.html", error="Invalid export type" ) + # Methods that will run continously: the update script for the heating # and the flask webapp + def updater(): while True: boiler.update() diff --git a/templates/export_choice.html b/templates/export_choice.html index 2ed6b11..00fbc08 100644 --- a/templates/export_choice.html +++ b/templates/export_choice.html @@ -7,7 +7,9 @@ </head> <body> <a href="/"> <p>Home</p> </a> - <a href="/export/pdf"> <p>Export as pdf</p> </a> - <a href="/export/csv"> <p>Export as csv</p> </a> - <a href="/api/info"> <p>Use API</p> </a> + <p>Text exports of database</a> + <a href="/export/temperature"> <p>Export temperature</p> </a> + <a href="/export/weather"> <p>Export weather</p> </a> + <a href="/export/history"> <p>Export history</p> </a> + <a href="/export/schedule"> <p>Export schedule</p> </a> </body> @@ -49,4 +49,3 @@ class weather_met_no(weather): return 0 except: return -1 - |
