forked from axsddlr/vlrggapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvlr_router.py
88 lines (74 loc) · 2.11 KB
/
vlr_router.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
80
81
82
83
84
85
86
87
88
from fastapi import APIRouter, Query, Request
from slowapi import Limiter
from slowapi.util import get_remote_address
from api.scrape import Vlr
router = APIRouter()
limiter = Limiter(key_func=get_remote_address)
vlr = Vlr()
@router.get("/news")
@limiter.limit("250/minute")
async def VLR_news(request: Request):
return vlr.vlr_news()
@router.get("/stats")
@limiter.limit("250/minute")
async def VLR_stats(
request: Request,
region: str = Query(..., description="Region shortname"),
timespan: str = Query(..., description="Timespan (30, 60, 90, or all)"),
):
"""
Get VLR stats with query parameters.
region shortnames:\n
"na": "north-america",\n
"eu": "europe",\n
"ap": "asia-pacific",\n
"sa": "latin-america",\n
"jp": "japan",\n
"oce": "oceania",\n
"mn": "mena"\n
"""
return vlr.vlr_stats(region, timespan)
@router.get("/rankings")
@limiter.limit("250/minute")
async def VLR_ranks(
request: Request, region: str = Query(..., description="Region shortname")
):
"""
Get VLR rankings for a specific region.
region shortnames:\n
"na": "north-america",\n
"eu": "europe",\n
"ap": "asia-pacific",\n
"la": "latin-america",\n
"la-s": "la-s",\n
"la-n": "la-n",\n
"oce": "oceania",\n
"kr": "korea",\n
"mn": "mena",\n
"gc": "game-changers",\n
"br": "Brazil",\n
"cn": "china",\n
"jp": "japan",\n
"col": "collegiate",\n
"""
return vlr.vlr_rankings(region)
@router.get("/match")
@limiter.limit("250/minute")
async def VLR_match(request: Request, q: str):
"""
query parameters:\n
"upcoming": upcoming matches,\n
"live_score": live match scores,\n
"results": match results,\n
"""
if q == "upcoming":
return vlr.vlr_upcoming_matches()
elif q == "live_score":
return vlr.vlr_live_score()
elif q == "results":
return vlr.vlr_match_results()
else:
return {"error": "Invalid query parameter"}
@router.get("/health")
def health():
return vlr.check_health()