2024-02-15 13:42:34 +00:00
|
|
|
from flask import g
|
|
|
|
from flask import current_app as app
|
|
|
|
|
|
|
|
import sqlite3, csv, os
|
2024-02-14 20:55:41 +00:00
|
|
|
|
|
|
|
DATABASE = "src/data/database.db"
|
|
|
|
|
|
|
|
def connect_db():
|
|
|
|
return sqlite3.connect(DATABASE)
|
|
|
|
|
2024-02-15 13:42:34 +00:00
|
|
|
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
|
|
|
|
|
2024-02-14 20:55:41 +00:00
|
|
|
def read_csv(file_path):
|
|
|
|
data = []
|
|
|
|
with open(file_path, 'r', newline='', encoding='utf-8') as csvfile:
|
|
|
|
reader = csv.DictReader(csvfile)
|
|
|
|
for row in reader:
|
|
|
|
data.append(row)
|
|
|
|
return data
|