🐛 hotfix: 天气拉取异常

This commit is contained in:
远野千束 2024-09-29 22:52:34 +08:00
parent 596f4d06ea
commit e6ea1b700f

View File

@ -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
@ -93,7 +94,7 @@ async def city_lookup(
"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())
@ -113,9 +114,9 @@ async def get_weather_now(
"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(
@ -133,9 +134,9 @@ async def get_weather_daily(
"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(
@ -153,9 +154,9 @@ async def get_weather_hourly(
"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(
@ -174,9 +175,9 @@ async def get_airquality(
"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,
@ -191,6 +192,6 @@ async def get_astronomy(
"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()