21 lines
481 B
Python
21 lines
481 B
Python
import secrets
|
|
from defs import app
|
|
from models.services.tip import TipAction
|
|
|
|
from typing import Dict, Optional
|
|
|
|
system_random = secrets.SystemRandom()
|
|
|
|
|
|
async def get_random_tips() -> Optional[Dict]:
|
|
tips = await TipAction.get_tips()
|
|
if not tips:
|
|
return None
|
|
num = system_random.randint(0, len(tips) - 1)
|
|
return tips[num].dict_tip()
|
|
|
|
|
|
@app.get("/get_tips")
|
|
async def get_tips():
|
|
return {"code": 200, "msg": "success", "data": await get_random_tips()}
|