# 綜合天氣 (https://nolantw.github.io/cwa/guides/weather/)

`cwa.weather.get()` 一次取得一個鄉鎮最常用的三種資料：預報、鄰近測站的目前天氣及生效中的警特報。做天氣 App 或通知時，通常從這裡開始就夠了。

```python
import cwa

weather = cwa.weather.get("臺北市信義區", days=3)

if weather.current:
    print("現在", weather.current.temperature)
if weather.today:
    print("今天降雨機率", weather.today.precipitation.max_probability)
for alert in weather.alerts:
    print(alert.title)
```

`days` 與[預報](/guides/forecast)相同，指定預報天數，預設為 7。

| 欄位 | 內容 | 詳細說明 |
| --- | --- | --- |
| `location` | 查詢的鄉鎮 | [指定地點](/guides/locations) |
| `as_of` | 查詢時間 | |
| `current` | 目前天氣，見下方；找不到符合條件的測站時為 `None` | [觀測值及測站](/guides/observations) |
| `forecast` | 完整預報 | [預報](/guides/forecast) |
| `today`、`tomorrow` | 今天及明天的預報，等同 `forecast.today`、`forecast.tomorrow`；預報未涵蓋該日時為 `None` | [預報](/guides/forecast#每日欄位) |
| `alerts` | 影響此鄉鎮的警特報，可直接以 `for` 逐一取出 | [警特報](/guides/alerts) |

## 目前天氣

`current` 取自 10 公里內、兩小時內有觀測值的最近測站，該測站可能位於相鄰鄉鎮。

`current` 本身可直接取得以下欄位：

| 欄位 | 說明 |
| --- | --- |
| `current.station` | 回報的測站，例如 `current.station.name` |
| `current.distance_km` | 測站到查詢鄉鎮代表點的距離（km） |
| `current.observed_at` | 觀測時間 |
| `current.temperature` | 氣溫（°C） |

濕度、氣壓、風、雨量及天氣現象在 `current.observation` 中：

```python
if weather.current:
    observation = weather.current.observation
    print(observation.humidity, observation.pressure, observation.wind.speed, observation.precipitation.millimetres)
```

各欄位的單位及缺值意義見[觀測值及測站](/guides/observations#觀測欄位)。需要調整距離或時間條件時，改用 `cwa.observations.nearest()`。

## 多個鄉鎮

傳入縣市或清單時，回傳以鄉鎮為鍵的結果；`get_all()` 查詢全臺所有鄉鎮。見[批次查詢與匯出](/advanced/batch)。