From 1ca19f43c131d77f18008dde867e76153288de38 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 3 Feb 2022 18:08:28 +0000 Subject: Exports and formatting. Reformatting. --- api.py | 2 ++ dates.py | 4 +--- heating.py | 9 +++++++-- main.py | 18 ++++++++++++------ templates/export_choice.html | 8 +++++--- weather.py | 1 - 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/api.py b/api.py index 46d7635..11abd44 100644 --- a/api.py +++ b/api.py @@ -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) diff --git a/dates.py b/dates.py index 77df9ab..2fbd763 100644 --- a/dates.py +++ b/dates.py @@ -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")) - - diff --git a/heating.py b/heating.py index 472b00a..d6cb7cf 100644 --- a/heating.py +++ b/heating.py @@ -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)), ) """ diff --git a/main.py b/main.py index d6d6320..22cdbbf 100644 --- a/main.py +++ b/main.py @@ -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/") 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 @@

Home

-

Export as pdf

-

Export as csv

-

Use API

+

Text exports of database +

Export temperature

+

Export weather

+

Export history

+

Export schedule

diff --git a/weather.py b/weather.py index 755f847..abc4112 100644 --- a/weather.py +++ b/weather.py @@ -49,4 +49,3 @@ class weather_met_no(weather): return 0 except: return -1 - -- cgit v1.2.3