datagokr — 에어코리아 대기오염정보
Fetch real-time air quality. Clean columns: station, measured_at, khai/khai_grade
(통합대기환경지수), and per pollutant a value + _grade + _flag: pm10/pm25 (미세먼지·
초미세먼지, ㎍/㎥, integers), so2/co/o3/no2 (ppm, decimals). Grades: 1 좋음 · 2 보통 ·
3 나쁨 · 4 매우나쁨.
| operation | 조회 |
|---|---|
by_sido |
시도별 실시간 (a province's stations, latest) |
by_station |
측정소별 실시간 (one station over a term) |
Prerequisite
pipx install pydatagokr # or: pip install pydatagokr
Never print the key value (the DATAGOKR_API_KEY env var or credentials.json) to output, logs, or a summary -- if you need to check which form it is (encoding vs decoding), ask the user.
A data.go.kr decoding key must be configured (env DATAGOKR_API_KEY or
~/.config/pydatagokr/credentials.json), and the 대기오염정보 dataset (service B552584)
applied for (활용신청). It is 자동승인 for a development account.
Running
datagokr airquality by_sido <시도명> [--json]
datagokr airquality by_station <측정소명> [--data-term TERM] [--json]
<시도명>: 서울 / 부산 / 인천 / 경기 / ... (a 광역시도).<측정소명>: a station, e.g. 종로구.--data-termisDAILY(default) /MONTH/3MONTH.
Procedure
- Pick the query. "서울 미세먼지" ->
by_sido 서울; a named station over time ->by_station <name> --data-term MONTH. - Run.
Adddatagokr airquality by_sido 서울--jsonfor machine-readable data. - Relay the result. Report
pm10/pm25with their grade (좋음/보통/나쁨/매우나쁨). A_flagvalue means that pollutant's measurement was unavailable. - Error handling. A one-line
datagokr: <message>on stderr:- a
[30]/[20]auth error -> the key is wrong, is the encoding form, or service B552584 is not applied for yet. - a
SERVICETIMEOUT(by_stationespecially) is a transient AirKorea server timeout -- retry.
- a
What this skill does not do
- It does not re-implement fetching or parsing (the package does); it always calls the CLI.
- It does not forecast; it returns measurements. (Air-quality forecasts are a separate operation not wrapped here.)