-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (41 loc) · 1.33 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
import uvicorn
from fastapi import FastAPI, Response, BackgroundTasks
import io
import strava
import finance
app = FastAPI()
# https://fastapi.tiangolo.com/advanced/behind-a-proxy/
# root_path = "/ludw"
# bez przedrostka -> funkcje implementowane bezpośrednio w main.py
# s -> strava.py
# /s/suffer
# /s/flash
# f -> finance.py
# /f/currency
@app.get("/health")
async def get_server_health():
return {"success": True, "message": "ludw strava server running"}
@app.get("/s/flash")
async def get_flash():
access_token = strava.get_access_token()
df = strava.get_strava_df(access_token)
return {
"success": True,
"message": strava.get_flash(df)
}
@app.get("/s/suffer")
async def get_suffer(btasks: BackgroundTasks):
access_token = strava.get_access_token()
df = strava.get_strava_df(access_token)
buf = io.BytesIO()
buf = strava.plot_suffer_score(df)
btasks.add_task(buf.close)
return Response(buf.getvalue(), media_type='image/png')
@app.get("/f/currency")
async def get_eur(btasks: BackgroundTasks):
buf = io.BytesIO()
buf = finance.get_cur_chart()
btasks.add_task(buf.close)
return Response(content=buf.getvalue(), media_type='image/png')
if __name__ == "__main__":
uvicorn.run("main:app", root_path="/ludw", host="0.0.0.0", port=5001, reload=True)