@ElPerinson

Как узнать, какая за окном погода через python-weather?

Как сделать какая за окном погода через библиотеку 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())
  • Вопрос задан
  • 850 просмотров
Ответы на вопрос 1
@versetty777
import weather

w = weather.Weather()

location = w.lookup_by_location('San Francisco')
condition = location.condition()
print(condition['temp'])
print(condition['text'])


lookup_by_location из библиотеки python-weather для получения информации о погоде в заданном местоположении
Ответ написан
Ваш ответ на вопрос

Вопрос закрыт для ответов и комментариев

Потому что уже есть похожий вопрос.
Похожие вопросы