LoginSignup
0
4

More than 1 year has passed since last update.

Python を用いて気象庁の天気予報APIから東京の天気を受け取る

Last updated at Posted at 2021-12-09

気象庁のAPI

2021年2月24日に気象庁が公式Twitterアカウントから気象庁のホームページをリニューアルしたことを発表した。リニューアルによって、気象庁公式の天気予報や概況のデータをJSON形式で取得できるようになった。

API取得方法

https://www.jma.go.jp/bosai/forecast/data/forecast/(pathCode).json

上記のURLは気象庁が出しているJSON形式の天気概況である。
(pathCode)の所に自分が知りたいエリアのコードを入力する。
東京のエリアコードは"130000"なので上記のURLに当てはめると下記の通りになる。

https://www.jma.go.jp/bosai/forecast/data/forecast/130000.json

エリアのコード(pathCode)一覧

API取得環境

Windows10
Python3.9.9
Visual Studio Code

API取得プログラム


import urllib.request as req

#URLを変数urlに保存
url='https://www.jma.go.jp/bosai/forecast/data/forecast/130000.json'

#保存ファイル名を指定する
filename='tenki.json'

#ダウンロード
req.urlretrieve(url,filename)

結果

キャプチャ.GIF
東京の天気概況を取得できました。

参考文献

Twitterで話題になった気象庁の天気予報APIをPythonで使ってみよう
新しい気象庁サイトからJSONデータが取得できる件

0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4