-
Notifications
You must be signed in to change notification settings - Fork 1
/
flask_app.py
79 lines (61 loc) · 2.07 KB
/
flask_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
71
72
73
74
75
76
77
78
79
from flask import Flask, render_template
from app.extensions import db, migrate
from app.views import *
from app.api.list_of_apis import *
from app.lib.log import *
from flask_cors import CORS
from flask_restful import Api
def create_app():
app = Flask(__name__)
app.config.from_pyfile('./app/config.py', silent=True)
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
register_blueprint(app)
register_extension(app)
api = Api(app)
api.add_resource(LaptimesQuery, '/api/laptimes/<int:season>/<int:id>')
with app.app_context():
db.create_all()
db.session.commit()
return app
def register_blueprint(app):
app.register_blueprint(view_blueprint)
app.register_blueprint(race_blueprint)
app.register_blueprint(results_blueprint)
app.register_blueprint(qualifying_blueprint)
app.register_blueprint(pitstops_blueprint)
app.register_blueprint(tyre_blueprint)
app.register_blueprint(rounded_laptimes_blueprint)
def register_extension(app):
db.init_app(app)
migrate.init_app(app)
app = create_app()
# To run the following custom flask functions:
# 1) export FLASK_APP=flask_app.py
# 2) flask get_results
@app.cli.command()
def get_results():
get_results_archive()
@app.cli.command()
def get_qual():
get_qual_archive()
# It takes about 5 minutes to process and save laptimes of one race to database
# An alternative would be to batch import csv containing laptimes data of all races from 2016 to present (import_csv_from_aws.py), but time difference to save a race is not much different from saving direction from Ergast API
@app.cli.command()
def get_laptimes():
get_laptimes_archive()
@app.cli.command()
def get_pitstops():
get_pitstops_archive()
@app.cli.command()
def get_races():
get_races_archive()
@app.cli.command()
def get_tyres():
get_tyres_archive()
@app.cli.command()
def recreate_db():
db.drop_all()
db.create_all()
#print(app.config);
if __name__ == '__main__':
app.run(host=app.config["API_SERVER_HOST"], port=app.config["API_SERVER_PORT"], debug=True)