mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-23 02:07:39 +08:00
🐛 hotfix: 天气拉取异常
This commit is contained in:
parent
596f4d06ea
commit
e6ea1b700f
@ -1,6 +1,7 @@
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from .qw_models import *
|
from .qw_models import *
|
||||||
|
import httpx
|
||||||
|
|
||||||
from ...utils.base.data_manager import get_memory_data
|
from ...utils.base.data_manager import get_memory_data
|
||||||
from ...utils.base.language import Language
|
from ...utils.base.language import Language
|
||||||
@ -23,8 +24,8 @@ def get_qw_lang(lang: str) -> str:
|
|||||||
async def check_key_dev(key: str) -> bool:
|
async def check_key_dev(key: str) -> bool:
|
||||||
url = "https://api.qweather.com/v7/weather/now?"
|
url = "https://api.qweather.com/v7/weather/now?"
|
||||||
params = {
|
params = {
|
||||||
"location": "101010100",
|
"location": "101010100",
|
||||||
"key" : key,
|
"key" : key,
|
||||||
}
|
}
|
||||||
async with aiohttp.ClientSession() as client:
|
async with aiohttp.ClientSession() as client:
|
||||||
resp = await client.get(url, params=params)
|
resp = await client.get(url, params=params)
|
||||||
@ -42,27 +43,27 @@ def get_local_data(ulang_code: str) -> dict:
|
|||||||
"""
|
"""
|
||||||
ulang = Language(ulang_code)
|
ulang = Language(ulang_code)
|
||||||
return {
|
return {
|
||||||
"monday" : ulang.get("weather.monday"),
|
"monday" : ulang.get("weather.monday"),
|
||||||
"tuesday" : ulang.get("weather.tuesday"),
|
"tuesday" : ulang.get("weather.tuesday"),
|
||||||
"wednesday" : ulang.get("weather.wednesday"),
|
"wednesday" : ulang.get("weather.wednesday"),
|
||||||
"thursday" : ulang.get("weather.thursday"),
|
"thursday" : ulang.get("weather.thursday"),
|
||||||
"friday" : ulang.get("weather.friday"),
|
"friday" : ulang.get("weather.friday"),
|
||||||
"saturday" : ulang.get("weather.saturday"),
|
"saturday" : ulang.get("weather.saturday"),
|
||||||
"sunday" : ulang.get("weather.sunday"),
|
"sunday" : ulang.get("weather.sunday"),
|
||||||
"today" : ulang.get("weather.today"),
|
"today" : ulang.get("weather.today"),
|
||||||
"tomorrow" : ulang.get("weather.tomorrow"),
|
"tomorrow" : ulang.get("weather.tomorrow"),
|
||||||
"day" : ulang.get("weather.day"),
|
"day" : ulang.get("weather.day"),
|
||||||
"night" : ulang.get("weather.night"),
|
"night" : ulang.get("weather.night"),
|
||||||
"no_aqi" : ulang.get("weather.no_aqi"),
|
"no_aqi" : ulang.get("weather.no_aqi"),
|
||||||
"now-windVelocity" : ulang.get("weather.now-windVelocity"),
|
"now-windVelocity" : ulang.get("weather.now-windVelocity"),
|
||||||
"now-humidity" : ulang.get("weather.now-humidity"),
|
"now-humidity" : ulang.get("weather.now-humidity"),
|
||||||
"now-feelsLike" : ulang.get("weather.now-feelsLike"),
|
"now-feelsLike" : ulang.get("weather.now-feelsLike"),
|
||||||
"now-precip" : ulang.get("weather.now-precip"),
|
"now-precip" : ulang.get("weather.now-precip"),
|
||||||
"now-pressure" : ulang.get("weather.now-pressure"),
|
"now-pressure" : ulang.get("weather.now-pressure"),
|
||||||
"now-vis" : ulang.get("weather.now-vis"),
|
"now-vis" : ulang.get("weather.now-vis"),
|
||||||
"now-cloud" : ulang.get("weather.now-cloud"),
|
"now-cloud" : ulang.get("weather.now-cloud"),
|
||||||
"astronomy-sunrise" : ulang.get("weather.astronomy-sunrise"),
|
"astronomy-sunrise" : ulang.get("weather.astronomy-sunrise"),
|
||||||
"astronomy-sunset" : ulang.get("weather.astronomy-sunset"),
|
"astronomy-sunset" : ulang.get("weather.astronomy-sunset"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -87,13 +88,13 @@ async def city_lookup(
|
|||||||
"""
|
"""
|
||||||
url = "https://geoapi.qweather.com/v2/city/lookup?"
|
url = "https://geoapi.qweather.com/v2/city/lookup?"
|
||||||
params = {
|
params = {
|
||||||
"location": location,
|
"location": location,
|
||||||
"adm" : adm,
|
"adm" : adm,
|
||||||
"number" : number,
|
"number" : number,
|
||||||
"key" : key,
|
"key" : key,
|
||||||
"lang" : lang,
|
"lang" : lang,
|
||||||
}
|
}
|
||||||
async with aiohttp.ClientSession() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
resp = await client.get(url, params=params)
|
resp = await client.get(url, params=params)
|
||||||
return CityLookup.parse_obj(resp.json())
|
return CityLookup.parse_obj(resp.json())
|
||||||
|
|
||||||
@ -108,14 +109,14 @@ async def get_weather_now(
|
|||||||
url_path = "v7/weather/now?"
|
url_path = "v7/weather/now?"
|
||||||
url = dev_url + url_path if dev else com_url + url_path
|
url = dev_url + url_path if dev else com_url + url_path
|
||||||
params = {
|
params = {
|
||||||
"location": location,
|
"location": location,
|
||||||
"key" : key,
|
"key" : key,
|
||||||
"lang" : lang,
|
"lang" : lang,
|
||||||
"unit" : unit,
|
"unit" : unit,
|
||||||
}
|
}
|
||||||
async with aiohttp.ClientSession() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
resp = await client.get(url, params=params)
|
resp = await client.get(url, params=params)
|
||||||
return await resp.json()
|
return resp.json()
|
||||||
|
|
||||||
|
|
||||||
async def get_weather_daily(
|
async def get_weather_daily(
|
||||||
@ -128,14 +129,14 @@ async def get_weather_daily(
|
|||||||
url_path = "v7/weather/%dd?" % (7 if dev else 30)
|
url_path = "v7/weather/%dd?" % (7 if dev else 30)
|
||||||
url = dev_url + url_path if dev else com_url + url_path
|
url = dev_url + url_path if dev else com_url + url_path
|
||||||
params = {
|
params = {
|
||||||
"location": location,
|
"location": location,
|
||||||
"key" : key,
|
"key" : key,
|
||||||
"lang" : lang,
|
"lang" : lang,
|
||||||
"unit" : unit,
|
"unit" : unit,
|
||||||
}
|
}
|
||||||
async with aiohttp.ClientSession() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
resp = await client.get(url, params=params)
|
resp = await client.get(url, params=params)
|
||||||
return await resp.json()
|
return resp.json()
|
||||||
|
|
||||||
|
|
||||||
async def get_weather_hourly(
|
async def get_weather_hourly(
|
||||||
@ -148,14 +149,14 @@ async def get_weather_hourly(
|
|||||||
url_path = "v7/weather/%dh?" % (24 if dev else 168)
|
url_path = "v7/weather/%dh?" % (24 if dev else 168)
|
||||||
url = dev_url + url_path if dev else com_url + url_path
|
url = dev_url + url_path if dev else com_url + url_path
|
||||||
params = {
|
params = {
|
||||||
"location": location,
|
"location": location,
|
||||||
"key" : key,
|
"key" : key,
|
||||||
"lang" : lang,
|
"lang" : lang,
|
||||||
"unit" : unit,
|
"unit" : unit,
|
||||||
}
|
}
|
||||||
async with aiohttp.ClientSession() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
resp = await client.get(url, params=params)
|
resp = await client.get(url, params=params)
|
||||||
return await resp.json()
|
return resp.json()
|
||||||
|
|
||||||
|
|
||||||
async def get_airquality(
|
async def get_airquality(
|
||||||
@ -169,14 +170,14 @@ async def get_airquality(
|
|||||||
url_path = f"airquality/v1/now/{location}?"
|
url_path = f"airquality/v1/now/{location}?"
|
||||||
url = dev_url + url_path if dev else com_url + url_path
|
url = dev_url + url_path if dev else com_url + url_path
|
||||||
params = {
|
params = {
|
||||||
"key" : key,
|
"key" : key,
|
||||||
"lang" : lang,
|
"lang" : lang,
|
||||||
"pollutant": pollutant,
|
"pollutant": pollutant,
|
||||||
"station" : station,
|
"station" : station,
|
||||||
}
|
}
|
||||||
async with aiohttp.ClientSession() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
resp = await client.get(url, params=params)
|
resp = await client.get(url, params=params)
|
||||||
return await resp.json()
|
return resp.json()
|
||||||
|
|
||||||
async def get_astronomy(
|
async def get_astronomy(
|
||||||
key: str,
|
key: str,
|
||||||
@ -187,10 +188,10 @@ async def get_astronomy(
|
|||||||
url_path = f"v7/astronomy/sun?"
|
url_path = f"v7/astronomy/sun?"
|
||||||
url = dev_url + url_path if dev else com_url + url_path
|
url = dev_url + url_path if dev else com_url + url_path
|
||||||
params = {
|
params = {
|
||||||
"key" : key,
|
"key" : key,
|
||||||
"location" : location,
|
"location" : location,
|
||||||
"date" : date,
|
"date" : date,
|
||||||
}
|
}
|
||||||
async with aiohttp.ClientSession() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
resp = await client.get(url, params=params)
|
resp = await client.get(url, params=params)
|
||||||
return await resp.json()
|
return resp.json()
|
Loading…
Reference in New Issue
Block a user