API 參考
綜合天氣
weather.get
def get(location: TownshipInput, *, days: int = 7) -> Weather
def get(location: BatchScope, *, days: int = 7, errors: Literal['raise'] = 'raise') -> WeatherCollection
def get(location: BatchScope, *, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Weather] 查詢指定鄉鎮的預報、鄰近測站觀測值及生效中的警特報。
參數
location鄉鎮名稱、鄉鎮物件、縣市或地點序列。days要查詢的臺灣日期天數,接受 1 到 7。errors批次查詢時可指定collect,保留成功及失敗項目。
回傳值
單筆綜合天氣或多筆結果。指定 errors="collect" 時回傳 BatchResult。
例外
ValueError天數超出範圍。BatchError批次有項目失敗,且errors為raise。
範例
from cwa import weather
result = weather.get("臺北市信義區", days=1) client.weather.get(location: TownshipInput, *, days: int = 7) -> Weather
client.weather.get(location: BatchScope, *, days: int = 7, errors: Literal['raise'] = 'raise') -> WeatherCollection
client.weather.get(location: BatchScope, *, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Weather]
await async_client.weather.get(location: TownshipInput, *, days: int = 7) -> Weather
await async_client.weather.get(location: BatchScope, *, days: int = 7, errors: Literal['raise'] = 'raise') -> WeatherCollection
await async_client.weather.get(location: BatchScope, *, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Weather] weather.get_all
def get_all(*, days: int = 7, errors: Literal['raise'] = 'raise') -> WeatherCollection
def get_all(*, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Weather] 查詢所有鄉鎮的綜合天氣。
client.weather.get_all(*, days: int = 7, errors: Literal['raise'] = 'raise') -> WeatherCollection
client.weather.get_all(*, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Weather]
await async_client.weather.get_all(*, days: int = 7, errors: Literal['raise'] = 'raise') -> WeatherCollection
await async_client.weather.get_all(*, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Weather] Weather
location: Township
as_of: datetime
current: LocatedObservation | None
forecast: Forecast
alerts: AlertSet
today: DayForecast | None
tomorrow: DayForecast | None 單一鄉鎮的天氣。無符合距離及時效條件的測站時,current 為 None。
WeatherCollection
class WeatherCollection 以鄉鎮為索引的綜合天氣。