26 lines
1.0 KiB
Python
26 lines
1.0 KiB
Python
import aiohttp
|
|
|
|
API_URL = "http://api:8000/subscription"
|
|
|
|
async def get_subscription(user_id: int):
|
|
async with aiohttp.ClientSession() as session:
|
|
async with session.get(f"{API_URL}/{user_id}") as resp:
|
|
if resp.status == 200:
|
|
data = await resp.json()
|
|
if data:
|
|
data["until"] = datetime.fromisoformat(data["until"])
|
|
return data
|
|
return None
|
|
|
|
async def set_subscription(user_id: int, uuid: str, until: datetime, months: int):
|
|
async with aiohttp.ClientSession() as session:
|
|
payload = {"user_id": user_id, "months": months}
|
|
async with session.post(f"{API_URL}/new", json=payload) as resp:
|
|
return await resp.json()
|
|
|
|
async def extend_subscription(user_id: int, months: int):
|
|
async with aiohttp.ClientSession() as session:
|
|
payload = {"user_id": user_id, "months": months}
|
|
async with session.post(f"{API_URL}/extend", json=payload) as resp:
|
|
return await resp.json()
|