aoirint_jmapy
Unofficial JMA weather forecast API wrapper in Python
気象庁天気予報データの非公式Pythonラッパー
2022-05-27時点のAPIに対応
- 気象庁の天気予報ページ: https://www.jma.go.jp/bosai/forecast/
- 気象庁ホームページ コンテンツの利用規約: https://www.jma.go.jp/jma/kishou/info/coment.html
Install
pip3 install aoirint_jmapy
Usage
東京都 東京地方のデータを見る例
from aoirint_jmapy import JmaApi, Telops
# UserAgentに含めるため、あなたのアプリケーション名、バージョンを設定することを推奨
# UserAgentは次のようになります: MyWeatherApp 0.1.0 / aoirint_jmapy 20220527.4
# アプリケーションを一般に配布する場合、不具合等により不特定多数の端末から
# 気象庁のサーバに負荷をかけることがないように、自分でキャッシュサーバを立てること等を推奨
# jma_url以下のパスを揃えると切り替えできる
jma = JmaApi(
jma_url='https://www.jma.go.jp',
app_name='MyWeatherApp',
app_version='0.1.0',
)
# 東京都
forecast = jma.forecast(area_id='130000')
print(forecast)
## 東京地方
print(forecast[0])
### 3日間予報
print(forecast[0].timeSeries[0])
### 週間予報
print(forecast[0].timeSeries[1])
### 3日間天気概況
overview_forecast = jma.overview_forecast(area_id='130000')
print(overview_forecast.text)
### 週間天気概況
overview_week = jma.overview_week(area_id='130000')
print(overview_week.text)
# WeatherCodeを対応するテキストにする(Third party contentsの項を参照)
weather_code = '101'
print(Telops[weather_code][3]) # 晴時々曇
area_idを調べる
- ※ 単一の地点のみでいい場合、気象庁の天気予報ページから手動で選択して実際のリクエストURLから抽出する方が簡単
# エリアリスト
area = jma.area()
## センターリスト(気象台リスト)
print(area.centers)
### 北海道地方: center_id=010100
#### 宗谷地方: area_id=011000
#### 上川・留萌地方: area_id=012000
print(area.centers['010100'])
### 関東甲信地方: center_id=010300
#### 東京都: area_id=130000
#### 神奈川県: area_id=140000
print(area.centers['010300'])
Supported data url list
- https://www.jma.go.jp/bosai/common/const/area.json
- https://www.jma.go.jp/bosai/forecast/const/forecast_area.json
- https://www.jma.go.jp/bosai/forecast/const/en_amedas.json
- https://www.jma.go.jp/bosai/forecast/const/anniversary.json
- https://www.jma.go.jp/bosai/forecast/const/week_area.json
- https://www.jma.go.jp/bosai/forecast/const/week_area05.json
- https://www.jma.go.jp/bosai/forecast/const/week_area_name.json
- https://www.jma.go.jp/bosai/forecast/data/overview_forecast/{area_id}.json
- https://www.jma.go.jp/bosai/forecast/data/overview_week/{area_id}.json
- https://www.jma.go.jp/bosai/forecast/data/forecast/{area_id}.json
- https://www.jma.go.jp/bosai/warning/data/warning/{area_id}.json
Third party contents
「晴」「曇後雨」などのテキストは、API中でweatherCodeという数値IDで識別されます。
この数値IDに対応するテキストはAPIから取得できず、JavaScriptコードとして埋め込まれています。
利便性のため、この辞書をダンプしたものをライブラリに同梱し、コード中から参照できるようにしています。
aoirint_jmapy/static/const_telops.json- データの出典: 気象庁ホームページ https://www.jma.go.jp/bosai/forecast/
- 気象庁ホームページ コンテンツの利用規約: https://www.jma.go.jp/jma/kishou/info/coment.html
Update const_telops.json
https://www.jma.go.jp/bosai/forecast/を開く。 開発者ツールで以下を実行、出力をコピーして貼り付けする。
console.log(JSON.stringify(Forecast.Const.TELOPS))
Development
Environment
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
Lock dependencies
pip3 install pip-tools
pip-compile requirements.in
pip-compile requirements.test.in
Test
# Download some JMA API response for test
./get_testdata.sh
pip3 install -r requirements.test.txt
mypy aoirint_jmapy/
pytest tests/
Release
GitHub Releaseを作成するとGitHub Actionsにより自動でPyPIにリリースされる。
Metadata
Release files for aoirint-jmapy 20220527.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aoirint_jmapy-20220527.9.tar.gz | 11.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aoirint_jmapy-20220527.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.5 kB
Release files / aoirint_jmapy-20220527.9.tar.gz
| Download URL | aoirint_jmapy-20220527.9.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3987ef928a3ab312bfc80619789ccea0b78bbe58e36c22bd202d1002e751e68a
|
|
BLAKE2b-256 checksum How to use checksums |
0990d7b8479150189913202dbe2071ade3adac123c7fb84c4229cdc82ba99c02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.13
|
Release files / aoirint_jmapy-20220527.9-py3-none-any.whl
| Download URL | aoirint_jmapy-20220527.9-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f73ce10258a98206d7aefdac9ac94b272b104ea3cf3a852d69ccf1614a56e94d
|
|
BLAKE2b-256 checksum How to use checksums |
816fe7c9e535787e0f35268724ab2486ec3786359da66a950d97a21b6b700cb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.13
|