Skip to content

Commit f3b1541

Browse files
committedNov 17, 2024·
feat: enhance the functionality of the tool.eat API.
1 parent 6014117 commit f3b1541

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed
 

‎src/routers/tool/basic.py

+50-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,61 @@
1+
import urllib.parse
12
import logging
23
from typing import List
3-
from fastapi import APIRouter, Query, Response
4+
from fastapi import APIRouter, Query
5+
from fastapi.responses import HTMLResponse
46

57
import random
68

7-
router = APIRouter(tags=["tool"], prefix="/api/tool")
9+
router = APIRouter(tags=["tool"], prefix="/tool")
810

911
logger = logging.getLogger(__file__)
1012

1113

1214
@router.get("/eat", summary="今天吃什么")
1315
def eat(choices: List[str] = Query(..., description="选择列表, 随机返回一个")):
14-
return Response(
15-
content=f"今天吃 {random.choice(choices)} !", headers={"content-type": "text/plain; charset=utf-8"}
16-
)
16+
select = random.choice(choices)
17+
meituanwaimai = urllib.parse.quote(f"meituanwaimai://waimai.meituan.com/search?query={select}")
18+
meituanwaimai_href = f"https://p.19940731.xyz/api/network/url/redirect?url={meituanwaimai}"
19+
20+
eleme = f"eleme://search?keyword={select}"
21+
eleme_href = f"https://p.19940731.xyz/api/network/url/redirect?url={eleme}"
22+
23+
dianping = f"dianping://searchshoplist?keyword={select}"
24+
dianping_href = f"https://p.19940731.xyz/api/network/url/redirect?url={dianping}"
25+
body = f"""
26+
<!DOCTYPE html>
27+
<html lang="zh">
28+
<head>
29+
<meta charset="UTF-8">
30+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
31+
<title></title>
32+
<style>
33+
.container {{
34+
text-align: center; /* 居中对齐 */
35+
margin-top: 50px; /* 上边距 */
36+
}}
37+
.main-text {{
38+
font-size: 24px; /* 大一点的文本 */
39+
}}
40+
.link {{
41+
font-size: 14px; /* 小一点的链接文本 */
42+
display: inline-block; /* 使链接在一行显示 */
43+
margin: 0 10px; /* 左右间距 */
44+
}}
45+
</style>
46+
</head>
47+
<body>
48+
<div class="container">
49+
<p class="main-text">今天吃 {select} !</p>
50+
<a href="{meituanwaimai_href}" class="link">点击跳转到美团外卖</a>
51+
<br>
52+
<br>
53+
<a href="{eleme_href}" class="link">点击跳转到饿了么</a>
54+
<br>
55+
<br>
56+
<a href="{dianping_href}" class="link">点击跳转到大众点评</a>
57+
</div>
58+
</body>
59+
</html>
60+
"""
61+
return HTMLResponse(content=body, headers={"content-type": "text/html; charset=UTF-8"})

0 commit comments

Comments
 (0)
Please sign in to comment.