From f315adea703193deb7419355dc084e903dbfde1e Mon Sep 17 00:00:00 2001 From: root Date: Sat, 15 Jan 2022 14:46:26 +0000 Subject: Development --- main.py | 85 +++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 31 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index c642d17..daae78f 100644 --- a/main.py +++ b/main.py @@ -1,56 +1,79 @@ -import sqlite3 +# Import other functions and classes import heating +import errors import sql -import time +import weather from flask import Flask, render_template app = Flask(__name__) -boiler = heating.rpi_heating() +# Paramaterised location of database file +# Use of constant +DBFILE = "data.db" -# paramaterised location of database file -# Use of final data type -global DBFILE -DBFILE = 'data.db' +db = sql.db(DBFILE) +#weather = weather_met_no() -db = sql.db(dbfile) +# Check if running on correct device : defensive coding against running +# on the wrong device +try: + with open("/sys/firmware/devicetree/base/model", "r") as file: + device = file.read() +except: + errors.device_error() -@app.route('/') -@app.route('/index.html') -def index(): +if device.startswith("Raspberry Pi 4"): + boiler = heating.rpi_heating(db) +else: + errors.device_error() + + +def main_page(): # paramaterised location of template in 'templates' folder return render_template( - "main.html", - actual_temp = boiler.temp, - target_temp = boiler.target - ) + "main.html", + actual_temp=boiler.temperature, + target_temp=boiler.target + #forecast_temp=weather.temperature() + ) + + +@app.route("/") +@app.route("/index.html") +def index(): + return main_page() -@app.route('/up') + +@app.route("/up") def form(): boiler.up() - return render_template("main.html") + return main_page() + -@app.route('/down') +@app.route("/down") def activity(): - boilder.down() - return render_template("main.html") + boiler.down() + return main_page() + + +@app.route("/export") +def export_choice(): + return render_template("export_choice.html") + -@app.route('/export/') +@app.route("/export/") def export(opt): - if opt == 'txt': + if opt == "txt": pass - elif opt == 'pdf': + elif opt == "pdf": pass else: - return render_template('error.html', error="Invalid export type") + 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() +if __name__ == "__main__": + app.run(host="0.0.0.0") -- cgit v1.2.3