2021-05-23 13:45:14 +00:00
|
|
|
|
""" 查询食物嘌呤含量 """
|
|
|
|
|
|
|
|
|
|
# By tg @lowking0415
|
|
|
|
|
# extra requirements: bs4
|
|
|
|
|
from asyncio import sleep
|
|
|
|
|
from requests import get
|
2021-06-21 06:49:23 +00:00
|
|
|
|
from sys import executable
|
2022-01-18 08:47:20 +00:00
|
|
|
|
from pagermaid import version
|
2021-05-23 13:45:14 +00:00
|
|
|
|
from pagermaid.listener import listener
|
2021-12-18 16:26:42 +00:00
|
|
|
|
from pagermaid.utils import alias_command, pip_install
|
|
|
|
|
|
|
|
|
|
pip_install("bs4")
|
|
|
|
|
|
|
|
|
|
from bs4 import BeautifulSoup
|
2021-05-23 13:45:14 +00:00
|
|
|
|
from urllib import parse
|
|
|
|
|
|
2021-06-16 07:09:40 +00:00
|
|
|
|
|
|
|
|
|
@listener(is_plugin=True, outgoing=True, command=alias_command("pl"),
|
|
|
|
|
description="输入【-pl 食物名】查询食物嘌呤含量",
|
|
|
|
|
parameters="<食物名>")
|
2021-05-23 13:45:14 +00:00
|
|
|
|
async def pl(context):
|
|
|
|
|
action = context.arguments.split()
|
2021-11-02 15:43:39 +00:00
|
|
|
|
status = False
|
2021-05-23 13:45:14 +00:00
|
|
|
|
if len(action) == 1:
|
|
|
|
|
await context.edit("查询中 . . .")
|
|
|
|
|
|
|
|
|
|
st = action[0]
|
|
|
|
|
st = st.encode('gb2312')
|
2021-06-16 07:09:40 +00:00
|
|
|
|
m = {'tj_so': st, }
|
2021-05-23 13:45:14 +00:00
|
|
|
|
s = parse.urlencode(m)
|
2021-11-02 15:43:39 +00:00
|
|
|
|
for _ in range(2): # 最多重试2次
|
2021-05-23 13:45:14 +00:00
|
|
|
|
try:
|
2021-11-02 15:43:39 +00:00
|
|
|
|
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
|
2021-05-24 01:32:41 +00:00
|
|
|
|
htmlStr = plhtml.content.decode("gbk")
|
2021-05-23 13:45:14 +00:00
|
|
|
|
soup = BeautifulSoup(htmlStr, 'html.parser')
|
|
|
|
|
arr = soup.find_all(name='a', attrs={"class": "heise"}, limit=10)
|
|
|
|
|
result = ""
|
|
|
|
|
for a in arr:
|
2021-11-02 15:43:39 +00:00
|
|
|
|
if a.text is not None and a.text != "":
|
2021-05-23 13:45:14 +00:00
|
|
|
|
txt = a.text.replace("嘌呤含量", "➟ ")
|
|
|
|
|
result = f"{result}{txt}\n"
|
2021-05-24 01:44:23 +00:00
|
|
|
|
if result == "":
|
|
|
|
|
await context.edit("没有查到结果")
|
|
|
|
|
else:
|
|
|
|
|
await context.edit(result)
|
2021-11-02 15:43:39 +00:00
|
|
|
|
status = True
|
2021-05-23 13:45:14 +00:00
|
|
|
|
break
|
|
|
|
|
except:
|
2021-11-02 15:43:39 +00:00
|
|
|
|
await sleep(5)
|
2021-05-23 13:45:14 +00:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
if not status:
|
2021-11-02 15:43:39 +00:00
|
|
|
|
await context.edit(f"呜呜呜,试了2次都没查到呢")
|
2021-05-23 13:45:14 +00:00
|
|
|
|
else:
|
|
|
|
|
await context.edit(f"乱写什么东西呀!格式如下:\n"
|
|
|
|
|
f"【-pl 食物名】查询食物嘌呤含量")
|
2021-06-16 07:09:40 +00:00
|
|
|
|
|
2021-05-23 13:45:14 +00:00
|
|
|
|
try:
|
|
|
|
|
if not status:
|
|
|
|
|
await sleep(2)
|
|
|
|
|
else:
|
|
|
|
|
await sleep(10)
|
|
|
|
|
await context.delete()
|
|
|
|
|
except:
|
|
|
|
|
pass
|