1
0
forked from bot/app

轻雪天气更新

This commit is contained in:
2024-04-27 02:20:44 +08:00
parent 9cfdd375ca
commit 86c7b70e63
107 changed files with 616 additions and 273 deletions

View File

@ -1,6 +1,8 @@
from .qw_models import *
import httpx
from ...utils.base.data_manager import get_memory_data
from ...utils.base.language import Language
dev_url = "https://devapi.qweather.com/" # 开发HBa
com_url = "https://api.qweather.com/" # 正式环境
@ -17,6 +19,42 @@ def get_qw_lang(lang: str) -> str:
return lang
async def check_key_dev(key: str) -> bool:
url = "https://api.qweather.com/v7/weather/now?"
params = {
"location": "101010100",
"key" : key,
}
async with httpx.AsyncClient() as client:
resp = await client.get(url, params=params)
return resp.json().get("code") != "200" # 查询不到付费数据为开发版
def get_local_data(ulang_code: str) -> dict:
"""
获取本地化数据
Args:
ulang_code:
Returns:
"""
ulang = Language(ulang_code)
return {
"monday" : ulang.get("weather.monday"),
"tuesday" : ulang.get("weather.tuesday"),
"wednesday": ulang.get("weather.wednesday"),
"thursday" : ulang.get("weather.thursday"),
"friday" : ulang.get("weather.friday"),
"saturday" : ulang.get("weather.saturday"),
"sunday" : ulang.get("weather.sunday"),
"today" : ulang.get("weather.today"),
"tomorrow" : ulang.get("weather.tomorrow"),
"day" : ulang.get("weather.day"),
"night" : ulang.get("weather.night"),
}
async def city_lookup(
location: str,
key: str,
@ -54,7 +92,7 @@ async def get_weather_now(
location: str,
lang: str = "zh",
unit: str = "m",
dev: bool = True,
dev: bool = get_memory_data("is_dev", True),
) -> dict:
url_path = "v7/weather/now?"
url = dev_url + url_path if dev else com_url + url_path
@ -74,7 +112,7 @@ async def get_weather_daily(
location: str,
lang: str = "zh",
unit: str = "m",
dev: bool = True,
dev: bool = get_memory_data("is_dev", True),
) -> dict:
url_path = "v7/weather/%dd?" % (7 if dev else 30)
url = dev_url + url_path if dev else com_url + url_path
@ -94,7 +132,7 @@ async def get_weather_hourly(
location: str,
lang: str = "zh",
unit: str = "m",
dev: bool = True,
dev: bool = get_memory_data("is_dev", True),
) -> dict:
url_path = "v7/weather/%dh?" % (24 if dev else 168)
url = dev_url + url_path if dev else com_url + url_path
@ -115,7 +153,7 @@ async def get_airquality(
lang: str,
pollutant: bool = False,
station: bool = False,
dev: bool = True
dev: bool = get_memory_data("is_dev", True),
) -> dict:
url_path = f"airquality/v1/now/{location}?"
url = dev_url + url_path if dev else com_url + url_path