127 lines
3.8 KiB
Python
127 lines
3.8 KiB
Python
#sys imports
|
|
from flask import Flask
|
|
from flask_restful import Resource, Api
|
|
from flask import render_template
|
|
from flask_restful_swagger import swagger
|
|
import logging
|
|
from datetime import datetime
|
|
# from flask_sqlalchemy import SQLAlchemy
|
|
# from app import db
|
|
# import pypyodbc
|
|
|
|
|
|
#user import
|
|
from Controllers.testcontroller import *
|
|
# from Controllers.WorkingController import WorkingController
|
|
from Controllers.testclass import Test
|
|
|
|
# from routes import initialize_routes
|
|
from services.db import db
|
|
from services.PandsSampleDataDrameServeice import *
|
|
# from services.MyCustomJSONEncoder import MyJSONEncoder
|
|
from services.dbservice import DbService
|
|
from services.utilityservices import sendRestResponse #utility_blueprint
|
|
# import Controllers.testclass as testclass
|
|
|
|
app = Flask('cibil')
|
|
logFileName = './logs/'+datetime.now().strftime("%Y-%m-%d")+'.log';
|
|
|
|
########### LOG METHOD 1 #################
|
|
# logging.basicConfig(filename=logFileName,level=logging.WARNING, format=f'%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
|
|
logging.basicConfig(filename=logFileName,level=logging.DEBUG, format=f'%(asctime)s %(levelname)s : %(message)s')
|
|
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
|
|
########### LOG METHOD 1 #################
|
|
|
|
#######METHOD 2#########################
|
|
# logger = logging.getLogger(name='cibil')
|
|
# logger.setLevel(logging.DEBUG)
|
|
# handler = logging.FileHandler(filename=logFileName)
|
|
# handler.setLevel(logging.DEBUG)
|
|
# handler.setFormatter(logging.Formatter(
|
|
# '%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
|
# app.logger.addHandler(handler)
|
|
# app.logger.info('Manual INfo')
|
|
#######METHOD 2#########################
|
|
|
|
# app.json_encoder = MyJSONEncoder
|
|
dbConnectionString = DbService.getDBConnectionString()
|
|
# print(dbConnectionString)
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = dbConnectionString
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
# db = SQLAlchemy(app)
|
|
|
|
|
|
|
|
db.init_app(app)
|
|
api = Api(app)
|
|
api = swagger.docs(api, apiVersion='0.1')
|
|
# init_app()
|
|
|
|
|
|
# result = db.engine.execute("SELECT id,charge_type,charge_type_description,created_at,modified_at FROM charge_type")
|
|
# print(result)
|
|
# for i in result:
|
|
# print(i)
|
|
|
|
|
|
# REST API's
|
|
class HelloWorld(Resource):
|
|
def get(self):
|
|
return {'hello': 'world'}
|
|
|
|
class TestFunction(Resource):
|
|
def get(self):
|
|
return testFunction()
|
|
|
|
class TestingClass(Resource):
|
|
def get(self):
|
|
print(self)
|
|
return(Test().testFunction2())
|
|
|
|
class TestDB(Resource):
|
|
def get(self):
|
|
# return(testDBcon())
|
|
return sendRestResponse(data = testDBcon())
|
|
|
|
api.add_resource(HelloWorld, '/api/')
|
|
api.add_resource(TestFunction, '/api/test')
|
|
api.add_resource(TestingClass, '/api/testclass')
|
|
api.add_resource(TestDB, '/api/db')
|
|
|
|
|
|
# Normal FLask routes
|
|
|
|
@app.route("/")
|
|
def hello_world():
|
|
app.logger.info('Manual INfo')
|
|
# app.logger.warning('Manual Warning')
|
|
# app.logger.error('Manual error')
|
|
# app.logger.critical('Manual critical')
|
|
return "<p>Hello, World!</p>"
|
|
|
|
@app.route("/aboutme/<string:name>")
|
|
def about(name=None):
|
|
# app.logger.info('Manual INfo')
|
|
# app.logger.warning('Manual Warning')
|
|
# app.logger.error('Manual error')
|
|
# app.logger.critical('Manual critical')
|
|
# print(name)
|
|
return render_template('about.html', name=name)
|
|
|
|
@app.route("/dataframe")
|
|
def dataframe():
|
|
dateframe = getDataFrame()
|
|
|
|
return render_template('dataframe.html', tables=[dateframe.to_html(classes='data')], titles=dateframe.columns.values)
|
|
|
|
@app.route("/cibildf")
|
|
def cibildataframe():
|
|
dateframe = getCIBILDataFrame()
|
|
|
|
return render_template('dataframe.html', tables=[dateframe.to_html(classes='data')], titles=dateframe.columns.values)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
from routes import initialize_routes
|
|
initialize_routes(api)
|
|
app.run(debug=True) |