1
0

More than 1 year has passed since last update.

海しるAPIを使ってみる その2

Last updated at Posted at 2021-10-20

海しるAPIを使ってみるの続き。

海洋速報のデータを取得するAPI

まずはJSON出力。

必須項目はないものの、日付を指定しないとすごい量のデータが出てくるので、それだけは指定したい。日付はUNIX時間で記述するので、変換ツールを使いながら入力。

海しるAPIポータルで作成したHTTPのコード。

GET https://api.msil.go.jp/oceanography/current-observation/quick-bulletin/v1/query?units=meter&time=1634569200000&returnGeometry=true&type=kuroshio HTTP/1.1

Cache-Control: no-cache
Ocp-Apim-Subscription-Key: 0e83ad5d93214e04abf37c970c32b641

python3で。

import requests
r_uri = "https://api.msil.go.jp/oceanography/current-observation/quick-bulletin/v1/query?units=meter&time=1634569200000&returnGeometry=true&type=kuroshio HTTP/1.1"
headers = {
# Request headers
'Cache-Control': 'no-cache',
'Ocp-Apim-Subscription-Key': '0e83ad5d93214e04abf37c970c32b641',
}
r_get = requests.get(r_uri,headers=headers)
print(r_get.status_code)
print(r_get.json())

画像出力。こちらはバウンディングボックスと時刻が必須。

python3で。

import requests
r_uri = "https://api.msil.go.jp/oceanography/current-observation/quick-bulletin/v1/export?bbox=135.0%2C30.0%2C140.0%2C40.0&time=1634569200000&transparent=false&dpi=96"
headers = {
# Request headers
'Cache-Control': 'no-cache',
'Ocp-Apim-Subscription-Key': '0e83ad5d93214e04abf37c970c32b641',
}
r_get = requests.get(r_uri,headers=headers)
print(r_get.status_code)
file_name = "png.png"
with open(file_name,"wb") as aaa:
    aaa.write(r_get.content)

参考にした記事

1
0
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
1
0