-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (62 loc) · 2.21 KB
/
main.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
import os
import logging
from flask import Flask, render_template, jsonify
import firebase_admin
from models import db
from routes.pages import pages
from routes.api import api
from routes.cron import cron
from config import Config, DevConfig
# check if running on Google App Engine
# (just checking for one of the environment variables found here: https://cloud.google.com/appengine/docs/standard/python3/runtime#environment_variables)
if ('GAE_APPLICATION' in os.environ):
# integrate Python logging module with Google Cloud Logging (captures INFO level and higher by default)
import google.cloud.logging
gcloudLoggingClient = google.cloud.logging.Client()
gcloudLoggingClient.get_default_handler()
gcloudLoggingClient.setup_logging()
logging.info('Running on Google App Engine')
# initialize Firebase Admin SDK
firebase_admin.initialize_app()
def createApp(configObj):
"""
Returns a Flask app configured with the given configuration object.
"""
app = Flask(__name__)
app.config.from_object(configObj)
# register blueprints
app.register_blueprint(pages)
app.register_blueprint(api)
app.register_blueprint(cron)
# initialize database connection
db.init_app(app)
# application to convert the probability to risk factor in html.jinja
@app.context_processor
def my_utility_processor():
def probabilityToRisk(closureValue):
flag = ""
if(closureValue == 1):
flag = "Very Low"
elif(closureValue == 2):
flag = "Low"
elif(closureValue == 3):
flag = "Moderate"
elif(closureValue == 4):
flag = "High"
elif(closureValue == 5):
flag = "Very High"
return flag
return dict(probabilityToRisk=probabilityToRisk)
return app
app = None
# if running the file directly
if __name__ == '__main__':
logging.info('Starting app with development configuration')
# setup for running locally (development configuration)
app = createApp(DevConfig())
# run the app locally
app.run(host=DevConfig.HOST, port=DevConfig.PORT, debug=True)
else: # else the app is being run from a WSGI application such as gunicorn
logging.info('Starting app with production configuration')
# setup for production configuration
app = createApp(Config())