all utility functions moved to src/util/utils
This commit is contained in:
parent
63a468046e
commit
133e4805fd
21
app.py
21
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():
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user