Skip to main content

aoirint_jmapy

Unofficial JMA weather forecast API wrapper in Python

気象庁天気予報データの非公式Pythonラッパー

2022-05-27時点のAPIに対応

Install

pip3 install aoirint_jmapy

Usage

東京都 東京地方のデータを見る例

from aoirint_jmapy import JmaApi, Telops

# UserAgentに含めるため、あなたのアプリケーション名、バージョンを設定することを推奨
# UserAgentは次のようになります: MyWeatherApp 0.1.0 / aoirint_jmapy 20220527.4
# アプリケーションを一般に配布する場合、不具合等により不特定多数の端末から
# 気象庁のサーバに負荷をかけることがないように、自分でキャッシュサーバを立てること等を推奨
# jma_url以下のパスを揃えると切り替えできる
jmaApi = JmaApi(
  jma_url='https://www.jma.go.jp',
  app_name='MyWeatherApp',
  app_version='0.1.0',
)

# 東京都
forecast = jmaApi.forecast(area_id='130000')
print(forecast)

## 東京地方
print(forecast[0])

### 3日間予報
print(forecast[0].timeSeries[0])

### 週間予報
print(forecast[0].timeSeries[1])

### 3日間天気概況
overview_forecast = jmaApi.overview_forecast(area_id='130000')
print(overview_forecast.text)

### 週間天気概況
overview_week = jmaApi.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 = jmaApi.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

Third party contents

「晴」「曇後雨」などのテキストは、API中でweatherCodeという数値IDで識別されます。 この数値IDに対応するテキストはAPIから取得できず、JavaScriptコードとして埋め込まれています。 利便性のため、この辞書をダンプしたものをライブラリに同梱し、コード中から参照できるようにしています。

Update const_telops.json

開発者ツールで以下を実行、出力をコピーして貼り付けする。

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にリリースされる。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aoirint_jmapy-20220527.8.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aoirint_jmapy-20220527.8-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file aoirint_jmapy-20220527.8.tar.gz.

File metadata

  • Download URL: aoirint_jmapy-20220527.8.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.13

File hashes

Hashes for aoirint_jmapy-20220527.8.tar.gz
Algorithm Hash digest
SHA256 ff95617e71e98df77ecf2b13d20f8c70e741fa426951cc3a2cf86af9dfb6df91
MD5 b2b295ca5c50e4ac4951ba56439b5104
BLAKE2b-256 a4065d539c6ddd3a71a5c519f0b992ff58cb2156cac01e89051bd94a827c97ec

See more details on using hashes here.

File details

Details for the file aoirint_jmapy-20220527.8-py3-none-any.whl.

File metadata

File hashes

Hashes for aoirint_jmapy-20220527.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0e00e9b3970255795a18ad0a0222223767ea27121b6961ec84013ac5c4621874
MD5 2b54c624329d3c8ab90f92fa0a4b4ba1
BLAKE2b-256 85f212d03e5b66f1ba214d529a0e929a230f8b3fda054313b15d5423b6ba4728

See more details on using hashes here.

Release history Release notifications | RSS feed

20220527.9

2 files

This release

20220527.8 This release

2 files

20220527.7

2 files

20220527.6

2 files

20220527.5

2 files

20220527.4

2 files

20220527.3

2 files

20220527.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page