mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
International information inquiry is supported
This commit is contained in:
parent
9a84c02bb5
commit
df0d15c1b3
48
.idea/workspace.xml
generated
Normal file
48
.idea/workspace.xml
generated
Normal file
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="ed635af3-c0b8-42b8-bec2-97a67519d2d6" name="变更" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/plugins/yiqing/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/plugins/yiqing/__init__.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Python Script" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectId" id="22hNoBlqrIEWzpMupKY3FkeSP6I" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="默认任务">
|
||||
<changelist id="ed635af3-c0b8-42b8-bec2-97a67519d2d6" name="变更" comment="" />
|
||||
<created>1640286031697</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1640286031697</updated>
|
||||
<workItem from="1640286033491" duration="1228000" />
|
||||
<workItem from="1640287304679" duration="2162000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
</project>
|
||||
@ -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__ = """
|
||||
@ -53,5 +53,13 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情失败"
|
||||
)
|
||||
else:
|
||||
rely=await get_yiqing_data(msg)
|
||||
if rely:
|
||||
await yiqing.send(rely)
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情失败"
|
||||
)
|
||||
else:
|
||||
await yiqing.send(f"{NICKNAME}没有查到{msg}的疫情查询...")
|
||||
73
plugins/yiqing/other_than.py
Normal file
73
plugins/yiqing/other_than.py
Normal file
@ -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=(.*?);</script>')
|
||||
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('伦敦'))
|
||||
Loading…
Reference in New Issue
Block a user