-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
79 lines (67 loc) · 2.66 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from flask import Flask, render_template
import os
import sqlite3
from flask_sqlalchemy import SQLAlchemy
from config import Config
import pyodbc, struct
from azure import identity
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
import urllib.parse
app=Flask(__name__)
# Define a class which contains my database information
#class Config:
# #SECRET_KEY = os.environ.get('SECRET_KEY') or 'your_secret_key' #####
# SQL_SERVER = 'aqll.database.windows.net'
# SQL_DATABASE = 'LivingLabDataApp'
# SQL_USER_NAME = 'aqll_admin'
# SQL_PASSWORD = 'aq11_pwd'
# SQL_DRIVER = '{ODBC Driver 17 for SQL Server}' ###
# SQLALCHEMY_DATABASE_URI = f'mssql+pyodbc://{SQL_USER_NAME}:{SQL_PASSWORD}@{SQL_SERVER}/{SQL_DATABASE}?driver={SQL_DRIVER}' ###
# SQLALCHEMY_TRACK_MODIFICATIONS = False
# Linking the app to the database
# Configure Database URI:
params = urllib.parse.quote_plus("Driver={ODBC Driver 18 for SQL Server};Server=tcp:aqll.database.windows.net,1433;Database=LivingLabDataApp;Uid=aqll_admin;Pwd=aq11_pwd;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;")
#app.config['SECRET_KEY'] = 'supersecret'
app.config['SQLALCHEMY_DATABASE_URI'] = "mssql+pyodbc:///?odbc_connect=%s" % params
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
#app.config["SQLALCHEMY_DATABASE_URI"] = '' # URI = my connection string
#app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///recipes.db' #where the database is stored
#app.config.from_object(Config) #where the database is stored (defined in the class earlier)
db = SQLAlchemy(app) #call SQLAlchemy - link the application and database together
# Create directories if needed
CPC_DIR = 'CPCFiles'
GPS_DIR = 'GPSFiles'
MAP_DIR = 'templates/maps'
DEL_DIR = 'deleted'
CPC_DEL_DIR = DEL_DIR + '/' + CPC_DIR
GPS_DEL_DIR = DEL_DIR + '/' + GPS_DIR
OPC_DIR = 'OPCFiles'
if not os.path.isdir(CPC_DIR):
os.mkdir(CPC_DIR)
if not os.path.isdir(MAP_DIR):
os.mkdir(MAP_DIR)
if not os.path.isdir(GPS_DIR):
os.mkdir(GPS_DIR)
if not os.path.isdir(DEL_DIR):
os.mkdir(DEL_DIR)
if not os.path.isdir(CPC_DEL_DIR):
os.mkdir(CPC_DEL_DIR)
if not os.path.isdir(GPS_DEL_DIR):
os.mkdir(GPS_DEL_DIR)
if not os.path.isdir(OPC_DIR):
os.mkdir(OPC_DIR)
# Define allowed file extensions for file uploads
ALLOWED_EXTENSIONS = set(['csv'])
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
# Set subdomain
subd = ""
## Let's try adding the index page with the map
@app.route('/')
def index():
return render_template('maps/average.html', settings=False) #subd=subd, settings=False)
if __name__ == '__main__':
app.run(debug=True)