mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-25 11:26:47 +00:00
pl 增加api超时提示以及代码逻辑优化 (#193)
This commit is contained in:
parent
2c070164e3
commit
2da0ef0959
@ -482,7 +482,7 @@
|
||||
},
|
||||
{
|
||||
"name": "pl",
|
||||
"version": "1.02",
|
||||
"version": "1.03",
|
||||
"section": "chat",
|
||||
"maintainer": "lowking",
|
||||
"size": "4.0 kb",
|
||||
|
18
pl.py
18
pl.py
@ -26,36 +26,42 @@ async def pl(context):
|
||||
await context.edit(f"请先安装依赖:\n`{executable} -m pip install bs4`\n随后,请重启 pagermaid。")
|
||||
return
|
||||
action = context.arguments.split()
|
||||
status = False
|
||||
if len(action) == 1:
|
||||
await context.edit("查询中 . . .")
|
||||
status = False
|
||||
|
||||
st = action[0]
|
||||
st = st.encode('gb2312')
|
||||
m = {'tj_so': st, }
|
||||
s = parse.urlencode(m)
|
||||
for _ in range(3): # 最多重试3次
|
||||
for _ in range(2): # 最多重试2次
|
||||
try:
|
||||
plhtml = get(f"http://www.gd2063.com/pl/?{s}")
|
||||
try:
|
||||
plhtml = get(f"http://www.gd2063.com/pl/?{s}", timeout=5)
|
||||
except:
|
||||
await context.edit("api请求异常,请访问\nhttp://www.gd2063.com/\n查看是否正常")
|
||||
status = True
|
||||
break
|
||||
htmlStr = plhtml.content.decode("gbk")
|
||||
soup = BeautifulSoup(htmlStr, 'html.parser')
|
||||
arr = soup.find_all(name='a', attrs={"class": "heise"}, limit=10)
|
||||
result = ""
|
||||
for a in arr:
|
||||
if (a.text != None):
|
||||
if a.text is not None and a.text != "":
|
||||
txt = a.text.replace("嘌呤含量", "➟ ")
|
||||
result = f"{result}{txt}\n"
|
||||
status = True
|
||||
if result == "":
|
||||
await context.edit("没有查到结果")
|
||||
else:
|
||||
await context.edit(result)
|
||||
status = True
|
||||
break
|
||||
except:
|
||||
await sleep(5)
|
||||
pass
|
||||
|
||||
if not status:
|
||||
await context.edit(f"呜呜呜,试了3次都没查到呢")
|
||||
await context.edit(f"呜呜呜,试了2次都没查到呢")
|
||||
else:
|
||||
await context.edit(f"乱写什么东西呀!格式如下:\n"
|
||||
f"【-pl 食物名】查询食物嘌呤含量")
|
||||
|
Loading…
Reference in New Issue
Block a user