-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.py
78 lines (63 loc) · 1.91 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
from flask import Flask, render_template, redirect, request, session, url_for
from flask_mysqldb import MySQL
import smtplib
import ssl
import re
import MySQLdb
import yaml
from authlib.integrations.flask_client import OAuth
import os
from utilities.dbConfig import database_config
from config.mysql import mysql
from config.OAuth import oauth
from dotenv import find_dotenv, load_dotenv
from routes.homeRoutes import home
from routes.detailsRoutes import details
from routes.authRoutes import auth
from routes.clubRoutes import clubs
from routes.student import student
from routes.adminAccess import admin
'''
loading environment variables using dotenv
'''
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path)
app = Flask(__name__)
DATABASE_URL = os.environ.get("CLEARDB_DATABASE_URL")
user, password, host, db = database_config(DATABASE_URL)
app.config['MYSQL_HOST'] = host
app.config['MYSQL_USER'] = user
app.config['MYSQL_PASSWORD'] = password
app.config['MYSQL_DB'] = db
''' MYSQL object initialization '''
mysql.init_app(app)
''' oauth object initialization '''
oauth.init_app(app)
app.secret_key = os.environ.get("secret_key")
app.register_blueprint(home)
app.register_blueprint(details)
app.register_blueprint(auth)
app.register_blueprint(clubs)
app.register_blueprint(student)
app.register_blueprint(admin)
@app.route("/mysql", methods=["POST"])
def run_queries():
'''
This Function runs mysql queries for testing routes
'''
data = request.form
print(data)
if(data['pwd'] == os.environ.get("secret_key")):
cur = mysql.connection.cursor()
cur.execute(data['q'])
mysql.connection.commit()
return "Done", 200
return "Failed", 404
@app.errorhandler(404)
def page_not_found(e):
return render_template('error.html')
if __name__ == "__main__":
if os.environ.get("env") == "dev":
app.run(debug=True)
else:
app.run()