diff --git a/app.py b/app.py index 8c9171f..08031d0 100644 --- a/app.py +++ b/app.py @@ -1,28 +1,11 @@ from flask import Flask, render_template, g, abort, request, jsonify, send_from_directory, url_for -import os - from src.util.utils import * app = Flask(__name__) - -@app.before_request -def before_request(): - g.db = connect_db() - - -@app.teardown_request -def teardown_request(exception): - if hasattr(g, "db"): - g.db.close() - - -def get_js_files(): - js_folder = os.path.join(app.static_folder, "js") - js_files = [f for f in os.listdir(js_folder) if f.endswith(".js")] - return js_files - +app.before_request(before_request) +app.teardown_request(teardown_request) @app.route("/") def show_app(): diff --git a/src/util/utils.py b/src/util/utils.py index aacf2c0..bb18767 100644 --- a/src/util/utils.py +++ b/src/util/utils.py @@ -1,10 +1,25 @@ -import sqlite3, csv +from flask import g +from flask import current_app as app + +import sqlite3, csv, os DATABASE = "src/data/database.db" def connect_db(): return sqlite3.connect(DATABASE) +def before_request(): + g.db = connect_db() + +def teardown_request(exception): + if hasattr(g, "db"): + g.db.close() + +def get_js_files(): + js_folder = os.path.join(app.static_folder, "js") + js_files = [f for f in os.listdir(js_folder) if f.endswith(".js")] + return js_files + def read_csv(file_path): data = [] with open(file_path, 'r', newline='', encoding='utf-8') as csvfile: