-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
59 lines (44 loc) · 1.43 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
import base64
import requests
from flask import Flask, request, send_file
from debrief.ergast import race_schedule
import debrief.fastf1
app = Flask(__name__)
statuses = {
'ok': 200,
'created': 201,
'badrequest': 400,
'unauthorized': 401,
'forbidden': 403,
'notfound': 404,
}
@app.route('/')
def hello_world(): # put application's code here
return 'Hello World!'
@app.route('/race-schedule/<year>')
def get_race_schedule(year):
response = race_schedule(int(year))
if response is None:
return f'Cannot fetch schedule for {year}.', statuses['notfound']
return response
@app.route('/fastest-laps/line-graph')
def get_line_graph():
x = request.args.get('x')
y = request.args.get('y')
year = int(request.args['year'])
gp = request.args['gp']
session = request.args['session']
drivers = request.args['drivers'].split(',')
response = debrief.fastf1.fastest_lap_of_driver(year, gp, session, drivers, x, y)
return base64.b64encode(response.read()).decode()
@app.route('/delta-time')
def get_delta_time():
year = int(request.args['year'])
gp = request.args['gp']
session = request.args['session']
drivers = request.args['drivers'].split(',')
lap = int(request.args['lap'])
response = debrief.fastf1.delta_time_between_drivers(year, gp, session, drivers, lap)
return base64.b64encode(response.read()).decode()
if __name__ == '__main__':
app.run()