diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..8001d1a --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn app:app \ No newline at end of file diff --git a/app.py b/app.py index 56d15b9..c731906 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,7 @@ import schedule import time import threading +from init_db import initializeDB def get_db_connection(): @@ -18,7 +19,9 @@ def get_db_connection(): return conn -app = Flask(__name__) +app = Flask(__name__, template_folder='Templates') +app.config['SECRET_KEY'] = 'secret123' +# app.config['EXPLAIN_TEMPLATE_LOADING'] = True @app.route('/') @@ -181,6 +184,15 @@ def add_url(): return redirect(url_for('dashboard')) +# Unique Endpoint protected By Secret ID to clear the database completely +@app.route('/clearAll/', methods=['GET']) +def clearDatabase(id): + print([id]) + if [id] == ['secret@key@to@delete@database@entries']: + initializeDB() + return redirect(url_for('register')) + + def checkFunction(): # get db conn print("checkFunction Called") @@ -214,7 +226,7 @@ def updateThread(): print("Update Thread Called") print(threading.current_thread().name) # schedule.every(1).minutes.do(checkFunction) - schedule.every(1).hours.do(checkFunction) + schedule.every(6).hours.do(checkFunction) while True: # print("While loop of updateThread") schedule.run_pending() @@ -233,11 +245,10 @@ def update(): return redirect(url_for("dashboard")) -if __name__ == "__main__": +@app.before_first_request +def thread_start(): threading.Thread(target=updateThread).start() - app.secret_key = 'secret123' # For Production/Deployment - app.run() - # For Development - # app.run(debug=True) +if __name__ == '__main__': + app.run(debug=True, threaded=True, use_reloader=False) diff --git a/database.db b/database.db index 5f8b025..e910e46 100644 Binary files a/database.db and b/database.db differ diff --git a/init_db.py b/init_db.py index 837ceb5..6f1c2f6 100644 --- a/init_db.py +++ b/init_db.py @@ -1,12 +1,11 @@ import sqlite3 -connection = sqlite3.connect('database.db') - -with open('schema.sql') as f: - connection.executescript(f.read()) - -cur = connection.cursor() -# will include querries to be run initially -connection.commit() -connection.close() +def initializeDB(): + connection = sqlite3.connect('database.db') + with open('schema.sql') as f: + connection.executescript(f.read()) + cur = connection.cursor() + # will include querries to be run initially + connection.commit() + connection.close() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..43a7fc0 Binary files /dev/null and b/requirements.txt differ