forked from React-Group/interstellar_ai
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
|
import python_weather
|
||
|
|
||
|
|
||
|
class Weather:
|
||
|
@staticmethod
|
||
|
async def getweather(unit_type, city):
|
||
|
|
||
|
if unit_type == "imperial":
|
||
|
unit_type = python_weather.IMPERIAL
|
||
|
elif unit_type == "metric":
|
||
|
unit_type = python_weather.METRIC
|
||
|
|
||
|
async with python_weather.Client(unit=unit_type) as client:
|
||
|
weather = await client.get(city)
|
||
|
|
||
|
data = {
|
||
|
'temperature': weather.temperature,
|
||
|
'humidity': weather.humidity,
|
||
|
'unit': weather.unit,
|
||
|
'datetime': weather.datetime,
|
||
|
'coordinates': weather.coordinates,
|
||
|
'country': weather.country,
|
||
|
'daily_forecasts': weather.daily_forecasts,
|
||
|
'description': weather.description,
|
||
|
'feels_like': weather.feels_like,
|
||
|
'kind': weather.kind,
|
||
|
'local_population': weather.local_population,
|
||
|
'locale': weather.locale,
|
||
|
'location': weather.location,
|
||
|
'precipitation': weather.precipitation,
|
||
|
'pressure': weather.pressure,
|
||
|
'region': weather.region,
|
||
|
'ultraviolet': weather.ultraviolet,
|
||
|
'visibility': weather.visibility,
|
||
|
'wind_direction': weather.wind_direction,
|
||
|
'wind_speed': weather.wind_speed,
|
||
|
}
|
||
|
|
||
|
return data
|