-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.py
63 lines (44 loc) · 1.79 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
__author__ = "Suyash Soni"
import json, logging
from flask_restful import Api
from settings import app, config
from mysql_connector import db
from util.logger import Logger
app.url_map.strict_slashes = False
api = Api(app)
def initialize_sqlalchemy():
""" Initializes MySQL database connection. """
config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://{username}:{password}@{host}:{port}/{database}'.format(
**config['MYSQL_DB_CONFIG']['URI_CONFIG']
)
config['MYSQL_CONNECTION_POOL_SIZE'] = config['MYSQL_DB_CONFIG']['MYSQL_CONNECTION_POOL_SIZE']
config['SQLALCHEMY_TRACK_MODIFICATIONS'] = config['DEBUG']
config['SQLALCHEMY_ECHO'] = config['DEBUG']
config['SQLALCHEMY_RECORD_QUERIES'] = config['DEBUG']
db.init_app(app)
# For creating the tables(via models) for the first time.
# import model
# app.app_context().push()
# db.create_all()
def init_logger():
log_level = getattr(logging, config['LOGGING']['LEVEL'], logging.INFO)
Logger.setLevel(log_level)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(logging.Formatter('[%(levelname)s -> %(name)s] at %(asctime)s in %(filename)s: %(lineno)s - %(message)s'))
Logger.addHandler(stream_handler)
logging.getLogger('sqlalchemy.engine.base.Engine').handlers = Logger.handlers
app.logger.handlers = Logger.handlers
app.logger.setLevel(log_level)
Logger.info('Initializing logger...')
init_logger()
initialize_sqlalchemy()
# Registering routes.
from routes import register_urls
register_urls(api)
@app.route("/")
@app.route("/api/v1/plagiarism")
def index():
return json.dumps({"message": "Welcome to Plagiarism Detector"})
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000, threaded=True)