python-weather icon indicating copy to clipboard operation
python-weather copied to clipboard

Is there a way to return the description/type for a day in the forecast?

Open thatgaypigeon opened this issue 2 years ago • 2 comments

As well as this specific question- is there documentation available anywhere? Or at least a big list of available commands/functions (such as 'weather.current.temperature')?

:D

thatgaypigeon avatar Aug 12 '22 23:08 thatgaypigeon

DailyForecast doesn't seem to have any text descriptions available for an entire daily forecast. I tackled this problem by taking all of the unique descriptions from the hourly forecasts within the daily, and joining them together:

import asyncio

import python_weather
from python_weather.forecast import CurrentForecast, DailyForecast

F = python_weather.IMPERIAL

def render_current(x: CurrentForecast) -> str:
    return f"{x.temperature}°{F}, {x.description}."

def render_daily(x: DailyForecast) -> str:
    t = f"{x.lowest_temperature}-{x.average_temperature}-{x.highest_temperature}"
    descriptions = ", ".join(set(h.description for h in x.hourly))
    emoji = "".join(map(repr, set(h.type for h in x.hourly)))
    return f"{x.date:%a}: {t}°{F}, {descriptions}. {emoji}"

async def print_weather():
    async with python_weather.Client(format=F) as client:
        weather = await client.get("Seattle")
        print(render_current(weather.current))
        for forecast in weather.forecasts:
            print(render_daily(forecast))

if __name__ == '__main__':
    asyncio.run(print_weather())
71°F, Clear.
Mon: 58-72-91°F, Sunny, Partly cloudy, Clear. ⛅️☀️
Tue: 56-70-88°F, Sunny, Clear. ☀️
Wed: 59-74-93°F, Sunny, Clear. ☀️

I don't see a docs page, but you can just browse the source directly: https://github.com/null8626/python-weather/blob/main/python_weather/forecast.py

wizpig64 avatar Aug 22 '22 10:08 wizpig64

I might add a documentation page in the future, development slowed down a lot because i am currently very busy. Sorry!

null8626 avatar Aug 25 '22 13:08 null8626

👍

thatgaypigeon avatar Dec 28 '22 00:12 thatgaypigeon