LoginSignup
2
3

More than 1 year has passed since last update.

【Python】Yahoo 気象情報API から雨量情報を取得してみた

Last updated at Posted at 2021-11-16

初めに

ダッシュボード作成のために、雨量をAPIにて取得する
YOLP 気象情報API を使用する。

リファレンスより引用
指定した緯度経度の雨の強さを取得できるAPIです。
現在時刻の降水強度実測値から、60分後までの降水強度予測値を取得できます。

環境

  • Windows10
  • Python 3.9.8

パラメータ

  • appid => Yahooデベロッパー登録をし、取得する
  • lat_lon => 経度,緯度(世界測地系)
  • output => 出力形式を指定(json/xml)
  • date =>日時を指定(YYYYMMDDHHMI形式)

本コードではyahoo_url.formatにてパラメータをセットしてください。

コード

yahoo_weather_api.py
# -*- coding:utf-8 -*-
import requests
import json
import datetime
now = datetime.datetime.now()

# Yahoo weather APIにて気象情報を取得する
yahoo_url = "https://map.yahooapis.jp/weather/V1/place?appid={appid}&coordinates={lat_lon}&output={output}&date={date}"
yahoo_url = yahoo_url.format(appid="xxxxxxxxxxxxxxxxxxxxxxxxx", lat_lon="135.0000000,34.000000", output="json",
                             date=now.strftime("%Y%m%d%H%M"))

yahoo_json = requests.get(yahoo_url).json()
yahoo_date = yahoo_json["Feature"][0]["Property"]["WeatherList"]["Weather"][0]["Date"]
yahoo_rainfall = yahoo_json["Feature"][0]["Property"]["WeatherList"]["Weather"][0]["Rainfall"]

# 出力
print(yahoo_date)
print(yahoo_rainfall)

終わりに

実測値といえども、気象レーダー解析雨量のため実際の降雨量と差異があるが、アメダスがない地点の雨量も取得できるのは魅力的。

※降水強度は、気象レーダーで観測された降水の強さを時間雨量(mm/h)に換算した値で、実際の雨量とは異なります。

参考サイト

2
3
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
2
3