mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-02 10:10:01 +08:00
update 0.0.6.2
This commit is contained in:
Regular → Executable
+31
-27
@@ -1,9 +1,8 @@
|
||||
from utils.user_agent import get_user_agent
|
||||
from configs.path_config import TEXT_PATH
|
||||
from typing import List
|
||||
from pathlib import Path
|
||||
from utils.http_utils import AsyncHttpx
|
||||
import ujson as json
|
||||
import aiohttp
|
||||
|
||||
china_city = Path(TEXT_PATH) / "china_city.json"
|
||||
|
||||
@@ -14,6 +13,10 @@ url = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
|
||||
|
||||
|
||||
async def get_yiqing_data(area: str):
|
||||
"""
|
||||
查看疫情数据
|
||||
:param area: 省份/城市
|
||||
"""
|
||||
global data
|
||||
province = None
|
||||
city = None
|
||||
@@ -32,31 +35,29 @@ async def get_yiqing_data(area: str):
|
||||
if area in data[p]:
|
||||
province = p
|
||||
city = area
|
||||
async with aiohttp.ClientSession(headers=get_user_agent()) as session:
|
||||
async with session.get(url, timeout=7) as response:
|
||||
epidemic_data = json.loads((await response.json())["data"])
|
||||
last_update_time = epidemic_data["lastUpdateTime"]
|
||||
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:
|
||||
data_ = [x for x in data_["children"] if x["name"] == city][0]
|
||||
except IndexError:
|
||||
return "未查询到..."
|
||||
confirm = data_["total"]["confirm"] # 累计确诊
|
||||
heal = data_["total"]["heal"] # 累计治愈
|
||||
dead = data_["total"]["dead"] # 累计死亡
|
||||
dead_rate = data_["total"]["deadRate"] # 死亡率
|
||||
heal_rate = data_["total"]["healRate"] # 治愈率
|
||||
now_confirm = data_["total"]["nowConfirm"] # 目前确诊
|
||||
suspect = data_["total"]["suspect"] # 疑似
|
||||
add_confirm = data_["today"]["confirm"] # 新增确诊
|
||||
epidemic_data = json.loads((await AsyncHttpx.get(url)).json()["data"])
|
||||
last_update_time = epidemic_data["lastUpdateTime"]
|
||||
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:
|
||||
data_ = [x for x in data_["children"] if x["name"] == city][0]
|
||||
except IndexError:
|
||||
return "未查询到..."
|
||||
confirm = data_["total"]["confirm"] # 累计确诊
|
||||
heal = data_["total"]["heal"] # 累计治愈
|
||||
dead = data_["total"]["dead"] # 累计死亡
|
||||
dead_rate = data_["total"]["deadRate"] # 死亡率
|
||||
heal_rate = data_["total"]["healRate"] # 治愈率
|
||||
now_confirm = data_["total"]["nowConfirm"] # 目前确诊
|
||||
suspect = data_["total"]["suspect"] # 疑似
|
||||
add_confirm = data_["today"]["confirm"] # 新增确诊
|
||||
x = f"{city}市" if city else f"{province}{province_type}"
|
||||
return (
|
||||
f"{x} 疫情数据:\n"
|
||||
@@ -75,6 +76,9 @@ async def get_yiqing_data(area: str):
|
||||
|
||||
|
||||
def get_city_and_province_list() -> List[str]:
|
||||
"""
|
||||
获取城市省份列表
|
||||
"""
|
||||
global data
|
||||
if not data:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user