Weather snapshots
A township's forecast, current conditions and warnings in one call.
cwa.weather.get() returns the three things most often needed for a township in one call: the forecast, current conditions from a nearby station and the active warnings. For a weather app or notifications, this is usually all you need.
import cwa
weather = cwa.weather.get("臺北市信義區", days=3)
if weather.current:
print("Now", weather.current.temperature)
if weather.today:
print("Chance of rain today", weather.today.precipitation.max_probability)
for alert in weather.alerts:
print(alert.title) days works as in
| Field | Contains | Details |
|---|---|---|
location | The queried township | |
as_of | Query time | |
current | Current conditions, see below; None when no station qualifies | |
forecast | The full forecast | |
today, tomorrow | The forecasts for today and tomorrow, same as forecast.today and forecast.tomorrow; None when not covered | |
alerts | Warnings affecting this township; loop over it with for |
Current weather
current comes from the nearest station within 10 km that has a reading from the last two hours. That station may be in a neighboring township.
These fields are available directly on current:
| Field | Description |
|---|---|
current.station | The reporting station, for example current.station.name |
current.distance_km | Distance from the station to the township’s reference point (km) |
current.observed_at | Observation time |
current.temperature | Air temperature (°C) |
Humidity, pressure, wind, rainfall and the weather condition are in current.observation:
if weather.current:
observation = weather.current.observation
print(observation.humidity, observation.pressure, observation.wind.speed, observation.precipitation.millimetres) See cwa.observations.nearest() instead.
Many townships
Pass a county or a list to get results keyed by township; get_all() covers every township in Taiwan. See