update v0.0.8.0

This commit is contained in:
HibiKier
2022-01-05 22:32:59 +08:00
parent 5e5168f804
commit 30b56583bd
47 changed files with 1521 additions and 1281 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
await yiqing.send(rely)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情失败"
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情成功"
)
else:
await yiqing.send(f"{NICKNAME}没有查到{msg}的疫情查询...")
+30 -25
View File
@@ -1,7 +1,10 @@
from configs.path_config import TEXT_PATH
from typing import List
from typing import List, Union
from pathlib import Path
from utils.http_utils import AsyncHttpx
from utils.image_utils import text2image
from utils.message_builder import image
from nonebot.adapters.cqhttp import MessageSegment
import ujson as json
china_city = Path(TEXT_PATH) / "china_city.json"
@@ -12,7 +15,7 @@ data = {}
url = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
async def get_yiqing_data(area: str):
async def get_yiqing_data(area: str) -> Union[str, MessageSegment]:
"""
查看疫情数据
:param area: 省份/城市
@@ -40,16 +43,16 @@ async def get_yiqing_data(area: str):
if area == "中国":
data_ = epidemic_data["areaTree"][0]
else:
data_ = [
x
for x in epidemic_data["areaTree"][0]["children"]
if x["name"] == province
][0]
if city:
try:
try:
data_ = [
x
for x in epidemic_data["areaTree"][0]["children"]
if x["name"] == province
][0]
if city:
data_ = [x for x in data_["children"] if x["name"] == city][0]
except IndexError:
return "未查询到..."
except IndexError:
return "未查询到..."
confirm = data_["total"]["confirm"] # 累计确诊
heal = data_["total"]["heal"] # 累计治愈
dead = data_["total"]["dead"] # 累计死亡
@@ -59,20 +62,22 @@ async def get_yiqing_data(area: str):
suspect = data_["total"]["suspect"] # 疑似
add_confirm = data_["today"]["confirm"] # 新增确诊
x = f"{city}市" if city else f"{province}{province_type}"
return (
f"{x} 疫情数据:\n"
f"\t目前确诊:\n"
f"\t\t确诊人数:{now_confirm}(+{add_confirm})\n"
f"\t\t疑似人数:{suspect}\n"
f"==================\n"
f"\t累计数据:\n"
f"\t\t确诊人数:{confirm}\n"
f"\t\t治愈人数:{heal}\n"
f"\t\t死亡人数:{dead}\n"
f"\t治愈率:{heal_rate}%\n"
f"\t死亡率:{dead_rate}%\n"
f"更新日期:{last_update_time}"
)
return image(b64=await text2image(
f"""
{x} 疫情数据:
目前确诊:
确诊人数:<f font_color=red>{now_confirm}(+{add_confirm})</f>
疑似人数:{suspect}
-----------------
累计数据:
确诊人数:<f font_color=red>{confirm}</f>
治愈人数:<f font_color=#39de4b>{heal}</f>
死亡人数:<f font_color=#191d19>{dead}</f>
治愈率:{heal_rate}%
死亡率:{dead_rate}%
更新日期:{last_update_time}
""", font_size=30, color="#f9f6f2"
))
def get_city_and_province_list() -> List[str]:
+43 -23
View File
@@ -6,8 +6,12 @@
# @File : other_than.py
# @Software: PyCharm
from utils.http_utils import AsyncHttpx
from nonebot.adapters.cqhttp import MessageSegment
from typing import Optional
from services.log import logger
from utils.image_utils import text2image
from utils.message_builder import image
from json.decoder import JSONDecodeError
import re
import json
@@ -23,50 +27,66 @@ def intcomma(value) -> str:
return new if orig == new else intcomma(new)
async def get_other_data(place: str) -> Optional[str]:
async def get_other_data(place: str, count: int = 0) -> Optional[MessageSegment]:
"""
:param place: 地名
:param count: 递归次数
:return: 格式化字符串
"""
if count == 5:
return None
try:
html = (
(await AsyncHttpx.get("https://news.ifeng.com/c/special/7uLj4F83Cqm"))
.text.replace("\n", "")
.replace(" ", "")
)
find_data = re.compile(r"varallData=(.*?);</script>")
sum_ = re.findall(find_data, html)[0]
sum_ = json.loads(sum_)
except JSONDecodeError:
return await get_other_data(place, count + 1)
except Exception as e:
logger.error(f"疫情查询发生错误 {type(e)}:{e}")
return None
find_data = re.compile(r"varallData=(.*?);</script>")
sum_ = re.findall(find_data, html)[0]
try:
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我暂时找不到
return image(
b64=await text2image(
f" {place} 疫情数据:\n"
"——————————————\n"
f" 新增病例:<f font_color=red>{intcomma(country['quezhen_add'])}</f>\n"
f" 现有确诊:<f font_color=red>{intcomma(country['quezhen_xianyou'])}</f>\n"
f" 累计确诊:<f font_color=red>{intcomma(country['quezhen'])}</f>\n"
f" 累计治愈:<f font_color=#39de4b>{intcomma(country['zhiyu'])}</f>\n"
f" 死亡:{intcomma(country['siwang'])}\n"
"——————————————"
# f"更新时间:{country['sys_publishDateTime']}"
# 时间无法精确到分钟,网页用了js我暂时找不到
,
font_size=30,
color="#f9f6f2",
padding=15
)
)
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 image(
b64=await text2image(
f"\n{place} 疫情数据:\n"
"——————————————\n"
f"\t新增病例:<f font_color=red>{intcomma(city['quezhen_add'])}</f>\n"
f"\t累计确诊:<f font_color=red>{intcomma(city['quezhen'])}</f>\n"
f"\t累计治愈:<f font_color=#39de4b>{intcomma(city['zhiyu'])}</f>\n"
f"\t死亡:{intcomma(city['siwang'])}\n"
"——————————————\n",
font_size=30,
color="#f9f6f2",
padding=15
)
)
except Exception as e:
logger.error(f"疫情查询发生错误 {type(e)}:{e}")