-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (50 loc) · 1.98 KB
/
main.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
import pathlib
from fastapi import FastAPI, Depends, Response, Request
from fastapi.responses import HTMLResponse
from routers import home
from routers import competition
from routers import results
from routers import riders
from routers import events
app = FastAPI()
home_dir = pathlib.Path('.')
app.include_router(home.router)
app.include_router(competition.router,
prefix='/competition',
tags=['competition'])
app.include_router(results.router,
prefix='/event_result',
tags=['results'])
app.include_router(riders.router,
prefix='/rider',
tags=['riders'])
app.include_router(events.router,
prefix='/event',
tags=['events'])
# @app.on_event('startup')
# async def startup_event():
# with Session(engine) as session:
# statement = select(Event)
# if session.exec(statement).first() is None:
# events_path = home_dir / 'data' / 'event_dates.json'
# with open(events_path) as events_file:
# events = json.load(events_file)['data']
# for event in events:
# session.add(Event(**event))
# session.commit()
# statement = select(Event)
# if session.exec(statement).first() is None:
# riders_path = home_dir / 'data' / 'riders.json'
# with open(riders_path) as riders_file:
# riders = json.load(riders_file)['data']
# for rider in riders:
# session.add(Event(**rider))
# session.commit()
# statement = select(EventResult)
# if session.exec(statement).first() is None:
# results_path = home_dir / 'data' / 'results.json'
# with open(results_path) as results_file:
# results = json.load(results_file)['data']
# for result in results:
# session.add(EventResult(**result))
# session.commit()