Как сделать какая за окном погода через библиотеку python-weather?
Вот код:
import python_weather
import asyncio
import os
import locale
locale.setlocale(locale.LC_ALL, ('ru_RU', 'UTF-8'))
async def getweather():
# declare the client. format defaults to the metric system (celcius, km/h, etc.)
async with python_weather.Client(format=python_weather.IMPERIAL) as client:
# fetch a weather forecast from a city
weather = await client.get("Крым")
celsius = (weather.current.temperature - 32) / 1.8
print(str(round(celsius)) + "°")
for forecast in weather.forecasts:
print(forecast.sky_text)
if __name__ == "__main__":
# see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
# for more details
if os.name == "nt":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(getweather())