-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
37 lines (28 loc) · 949 Bytes
/
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
import aiohttp
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from utils.roblox import get_user_data, get_user_groups, get_game_info
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/get-user")
async def get_user(username: str):
async with aiohttp.ClientSession() as session:
user_data = await get_user_data(username, session)
return user_data
@app.get("/users/{user_id}/groups")
async def get_groups(user_id: int):
async with aiohttp.ClientSession() as session:
groups = await get_user_groups(user_id, session)
return groups
@app.get("/games/{game_id}")
async def get_game(game_id: int):
async with aiohttp.ClientSession() as session:
game = await get_game_info(game_id, session)
return game