-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
70 lines (63 loc) · 2.01 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
from flask import Flask
from flask_restful import Api
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from flask_apispec.extension import FlaskApiSpec
from resource import Punch,Count,Curriculum,Leave,Course,Crawler,Login
# from flask_cors import CORS
from flask_jwt_extended import JWTManager
from datetime import timedelta
import os
from dotenv import load_dotenv
import logging
load_dotenv()
logging.basicConfig(filename = os.getenv("punchlog"),
level = logging.INFO,
format = "%(asctime)s %(message)s",
datefmt = "%d/%m/%Y %I:%M:%S %p")
app = Flask(__name__)
jwt = JWTManager(app)
# CORS(app)
api = Api(app)
app.config['JWT_SECRET_KEY'] = os.getenv("secretkey")
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(minutes = int(os.getenv("tokenexpires")))
app.config['PROPAGATE_EXCEPTIONS'] = True
app.config.update({
'APISPEC_SPEC': APISpec(
title = 'Erp Project API',
version = 'v1',
plugins = [MarshmallowPlugin()],
openapi_version = '2.0.0'
),
'APISPEC_SWAGGER_URL': '/api_doc',
'APISPEC_SWAGGER_UI_URL': '/',
'JSON_AS_ASCII': False,
'MAX_CONTENT_LENGTH': 1024 * 1024
})
docs = FlaskApiSpec(app)
@app.errorhandler(422)
@app.errorhandler(400)
def handle_error(err):
headers = err.data.get("headers", None)
messages = err.data.get("messages", ["Invalid request."])
logging.info(messages)
if headers:
return {"errors": messages}, err.code, headers
else:
return {"errors": messages}, err.code
api.add_resource(Punch,'/punch')
docs.register(Punch)
api.add_resource(Count,'/count')
docs.register(Count)
api.add_resource(Curriculum,'/curriculum')
docs.register(Curriculum)
api.add_resource(Leave,'/leave')
docs.register(Leave)
api.add_resource(Course,'/course')
docs.register(Course)
api.add_resource(Crawler,'/crawler')
docs.register(Crawler)
api.add_resource(Login,'/login')
docs.register(Login)
# if __name__ == '__main__':
# app.run('0.0.0.0', debug = True)