From ede54f9b22c55d90d37236c308031340d1fb0cd7 Mon Sep 17 00:00:00 2001 From: yzyyz1387 <1796031384@qq.com> Date: Fri, 24 Dec 2021 03:32:19 +0800 Subject: [PATCH] International information inquiry is supported --- .idea/inspectionProfiles/Project_Default.xml | 122 +++++++++++++++++++ .idea/vcs.xml | 6 + .idea/workspace.xml | 48 ++++++++ 0.0.6.2 | 0 0.0.6.3 | 0 0.0.6.4 | 0 0.0.6.5 | 0 0.0.6.6 | 0 0.0.7.0 | 0 0.0.7.1 | 0 plugins/yiqing/__init__.py | 8 +- plugins/yiqing/other_than.py | 73 +++++++++++ 12 files changed, 255 insertions(+), 2 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 0.0.6.2 create mode 100644 0.0.6.3 create mode 100644 0.0.6.4 create mode 100644 0.0.6.5 create mode 100644 0.0.6.6 create mode 100644 0.0.7.0 create mode 100644 0.0.7.1 create mode 100644 plugins/yiqing/other_than.py diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..5482f748 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,122 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..eea3155b --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + 1640286031697 + + + + + + \ No newline at end of file diff --git a/0.0.6.2 b/0.0.6.2 new file mode 100644 index 00000000..e69de29b diff --git a/0.0.6.3 b/0.0.6.3 new file mode 100644 index 00000000..e69de29b diff --git a/0.0.6.4 b/0.0.6.4 new file mode 100644 index 00000000..e69de29b diff --git a/0.0.6.5 b/0.0.6.5 new file mode 100644 index 00000000..e69de29b diff --git a/0.0.6.6 b/0.0.6.6 new file mode 100644 index 00000000..e69de29b diff --git a/0.0.7.0 b/0.0.7.0 new file mode 100644 index 00000000..e69de29b diff --git a/0.0.7.1 b/0.0.7.1 new file mode 100644 index 00000000..e69de29b diff --git a/plugins/yiqing/__init__.py b/plugins/yiqing/__init__.py index 29674c2e..0a571d3b 100755 --- a/plugins/yiqing/__init__.py +++ b/plugins/yiqing/__init__.py @@ -5,7 +5,7 @@ from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent from nonebot.typing import T_State from utils.utils import get_message_text from configs.config import NICKNAME - +from .other_than import get_other_data __zx_plugin_name__ = "疫情查询" __plugin_usage__ = """ @@ -54,4 +54,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State): f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情失败" ) else: - await yiqing.send(f"{NICKNAME}没有查到{msg}的疫情查询...") + rely=await get_yiqing_data(msg) + if rely: + await yiqing.send(rely) + else: + await yiqing.send(f"{NICKNAME}没有查到{msg}的疫情查询...") diff --git a/plugins/yiqing/other_than.py b/plugins/yiqing/other_than.py new file mode 100644 index 00000000..2eec1e97 --- /dev/null +++ b/plugins/yiqing/other_than.py @@ -0,0 +1,73 @@ +# python3 +# -*- coding: utf-8 -*- +# @Time : 2021/12/23 23:04 +# @Author : yzyyz +# @Email : youzyyz1384@qq.com +# @File : other_than.py +# @Software: PyCharm +import httpx +import re +import json +__doc__='''爬虫实现国外疫情数据(找不到好接口)''' + + +def intcomma(value): + """ + 数字格式化 + """ + orig = str(value) + new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig) + if orig == new: + return new + else: + return intcomma(new) + +async def get_other_data(place:str): + """ + :param place: 地名 + :return: 格式化字符串 + """ + try: + html = httpx.get('https://news.ifeng.com/c/special/7uLj4F83Cqm').text.replace('\n', '').replace(' ', '') + except: + return + find_data = re.compile(r'varallData=(.*?);') + sum = re.findall(find_data, html)[0] + sum = json.loads(sum) + other_country=sum['yiqing_v2']['dataList'][29]['child'] + for country in other_country: + if place==country['name2']: + return ( + f"{place} 疫情数据:\n" + "——————————————\n" + f"新增病例:{intcomma(country['quezhen_add'])}\n" + f"现有确诊:{intcomma(country['quezhen_xianyou'])}\n" + f"累计确诊:{intcomma(country['quezhen'])}\n" + f"累计治愈:{intcomma(country['zhiyu'])}\n" + f"死亡:{intcomma(country['siwang'])}\n" + "——————————————" + #f"更新时间:{country['sys_publishDateTime']}" + #时间无法精确到分钟,网页用了js我暂时找不到 + ) + else: + for city in country['child']: + if place==city['name3']: + return ( + f"{place} 疫情数据:\n" + "——————————————\n" + f"新增病例:{intcomma(city['quezhen_add'])}\n" + f"累计确诊:{intcomma(city['quezhen'])}\n" + f"累计治愈:{intcomma(city['zhiyu'])}\n" + f"死亡:{intcomma(city['siwang'])}\n" + "——————————————" + + ) + return + + +if __name__ == '__main__': + a=get_other_data('英国') + print(a) + # print(get_other_data('美国')) + # print(get_other_data('印度')) + # print(get_other_data('伦敦')) \ No newline at end of file