summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@turin.home>2022-02-03 18:08:28 +0000
committerroot <root@turin.home>2022-02-03 18:08:28 +0000
commit1ca19f43c131d77f18008dde867e76153288de38 (patch)
tree9423f24da815fee682b73189f03d18641c557b3e
parent333bdb9507ca82709d92fe8919a9b40fc02d7dc7 (diff)
Exports and formatting. Reformatting.
-rw-r--r--api.py2
-rw-r--r--dates.py4
-rw-r--r--heating.py9
-rw-r--r--main.py18
-rw-r--r--templates/export_choice.html8
-rw-r--r--weather.py1
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/<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>
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
-