summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py38
1 files changed, 34 insertions, 4 deletions
diff --git a/main.py b/main.py
index 7559888..2fdb0f9 100644
--- a/main.py
+++ b/main.py
@@ -5,6 +5,7 @@ import sql
import weather
import time
import sqlite3
+import dates
from flask import Flask, render_template, redirect, url_for
from threading import Thread
@@ -12,16 +13,24 @@ from threading import Thread
app = Flask(__name__)
+# TODO:
+# schedule
+# export as pdf (dictionary/merge sort)
+
+# Use of constants
# Paramaterised location of database file
-# Use of constant
DBFILE = "data.db"
+TIME_INCREMENT = 5
+# number of increments per day
+STEPS = (60 * 60 * 24) / TIME_INCREMENT
+# instantiate classes
db = sql.db(DBFILE)
-
+date = date.dates()
weather = weather.weather_met_no()
# Check if running on correct device : defensive coding against running
-# on the wrong device
+# on the wrong device, the instantiate heating class
try:
with open("/sys/firmware/devicetree/base/model", "r") as file:
device = file.read()
@@ -87,6 +96,23 @@ def export(opt):
with open("static/export.txt", "w") as file:
file.write(o)
return redirect("/static/export.txt")
+ elif opt == "pdf":
+ con = sqlite3.connect(DBFILE)
+ cur = con.cursor()
+ data = cur.execute("select date, on from history")
+ on = 0
+ total = 0
+ days = dictionary.dictionary()
+ for i in data:
+ if data[1] == 1:
+ days.inc(data[0], 1 / STEPS * 100)
+ days.sort_by_value()
+ con.close()
+ # writing data to a file
+ # with open("static/export.txt", "w") as file:
+ # file.write(o)
+ # return redirect("/static/export.txt")
+ return True
else:
return render_template(
"error.html", error="Invalid export type"
@@ -100,7 +126,11 @@ def export(opt):
def updater():
while True:
boiler.update()
- time.sleep(5)
+ db.exec(
+ "insert into weather values (?,?,?,?)",
+ (date.day(), date.time(), weather.temperature()),
+ )
+ time.sleep(TIME_INCREMENT)
def webapp():