diff --git a/list.json b/list.json index 5e9e3bb..0edc891 100644 --- a/list.json +++ b/list.json @@ -482,7 +482,7 @@ }, { "name": "pl", - "version": "1.02", + "version": "1.03", "section": "chat", "maintainer": "lowking", "size": "4.0 kb", diff --git a/pl.py b/pl.py index 64a2161..2f4e144 100644 --- a/pl.py +++ b/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 食物名】查询食物嘌呤含量")