From 8600370a572ee933cf538cb3dd6fa7098f477c7c Mon Sep 17 00:00:00 2001 From: root Date: Thu, 3 Feb 2022 18:23:37 +0000 Subject: Exporting to static file --- main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index f6bbb23..bfcb100 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import errors import sql import weather import time +import sqlite3 from flask import Flask, render_template, redirect, url_for from threading import Thread @@ -75,14 +76,16 @@ def export_choice(): def export(opt): # Defensive handling of input if opt in ["temperature", "weather", "history", "schedule"]: - con = sqlite3.connect(self.dbfile) + con = sqlite3.connect(DBFILE) cur = con.cursor() data = cur.exec("select * from {}".format(opt)) o = "" for i in data: o += str(a) + "\n" con.close() - return o + with open('static/export.txt', 'w') as file: + file.write(o) + return redirect('/static/export.txt') else: return render_template( "error.html", error="Invalid export type" -- cgit v1.2.3