-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
63 lines (50 loc) · 1.55 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
"""Main module for the RPN calculator application."""
import logging
from flask import Flask, redirect
from flask_restx import Api
from api.routes import create_routes
def configure_logging():
"""Configure logging for the application."""
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
filename='rpn_calculator.log'
)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
console_handler.setFormatter(formatter)
logging.getLogger('').addHandler(console_handler)
def create_app():
"""Create and configure the Flask application."""
configure_logging()
app = Flask(__name__)
logging.info("Flask application created")
api = Api(
app,
version='1.0',
title='RPN Calculator API',
description='API for RPN calculator',
doc='/'
)
logging.info("Flask-RESTX API configured")
rpn = create_routes(api)
api.add_namespace(rpn, path='/rpn')
logging.info("RPN routes added to API")
@app.route('/')
def index():
"""Root route redirecting to Swagger UI."""
logging.info("Redirecting to Swagger UI")
return redirect('/swagger')
return app
app = create_app()
if __name__ == '__main__':
logging.info("Starting the application")
app.run(
debug=True,
host='127.0.0.1',
port=5000,
use_reloader=False
)