summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..c642d17
--- /dev/null
+++ b/main.py
@@ -0,0 +1,56 @@
+import sqlite3
+import heating
+import sql
+import time
+
+from flask import Flask, render_template
+
+app = Flask(__name__)
+
+boiler = heating.rpi_heating()
+
+# paramaterised location of database file
+# Use of final data type
+global DBFILE
+DBFILE = 'data.db'
+
+
+db = sql.db(dbfile)
+
+@app.route('/')
+@app.route('/index.html')
+def index():
+ # paramaterised location of template in 'templates' folder
+ return render_template(
+ "main.html",
+ actual_temp = boiler.temp,
+ target_temp = boiler.target
+ )
+
+@app.route('/up')
+def form():
+ boiler.up()
+ return render_template("main.html")
+
+@app.route('/down')
+def activity():
+ boilder.down()
+ return render_template("main.html")
+
+@app.route('/export/<opt>')
+def export(opt):
+ if opt == 'txt':
+ pass
+ elif opt == 'pdf':
+ pass
+ else:
+ return render_template('error.html', error="Invalid export type")
+
+
+if __name__ == '__main__':
+ # if the database file does not exist, create it
+ try:
+ open(dbfile)
+ except:
+ sql.setup(dbfile)
+ app.run()