python-weather
python-weather copied to clipboard
Is there a way to return the description/type for a day in the forecast?
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
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
I might add a documentation page in the future, development slowed down a lot because i am currently very busy. Sorry!
👍