-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
62 lines (52 loc) · 1.84 KB
/
run.py
File metadata and controls
62 lines (52 loc) · 1.84 KB
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
"""run app"""
from app import create_app
from flask import make_response
from flask import jsonify
from app.models.comments_model import Comments
from app.models.answers_model import Answers
from app.models.questions_model import Questions
from app.models.user_model import Users
from app.models.votes_model import Votes
from app.models import database_connection
APP=create_app('development')
@APP.errorhandler(404)
def not_found(error):
"""customed error handler"""
return make_response(jsonify({"error": "no item found"}),404)
@APP.errorhandler(401)
def unauthorized(error):
"""customed error handler"""
return make_response(jsonify({"error": "Please Login first"}),401)
@APP.errorhandler(405)
def bad_method(error):
"""customed error handler"""
return make_response(jsonify({"error": "the method is not allowed"}),405)
@APP.errorhandler(500)
def internal_server(error):
"""customed error handler"""
return make_response(jsonify({"error": "sorry technical problem occurred"}),500)
@APP.errorhandler(400)
def bad_request(error):
'''return customed bad format'''
return make_response(jsonify({"error":"bad request format"}))
@APP.errorhandler(403)
def bad_request(error):
'''return customed bad format'''
return make_response(jsonify({"error":"Permission denied"}))
def Ini_init_database():
"""create database table when the app starts when the app """
connection=database_connection("development")
answers=Answers()
questions=Questions()
users=Users()
comment = Comments()
votes = Votes()
users.create_user_table(connection)
questions.create_question_table(connection)
answers.create_answer_table(connection)
votes.create_votes_table(connection)
comment.create_comment_table(connection)
if __name__=="__main__":
"""run the file"""
Ini_init_database()
APP.run()