LoginSignup
2
1

More than 5 years have passed since last update.

Bluemix API(Weather Company Dataサービス)

Last updated at Posted at 2017-12-30

コード

import requests 

import json

# API認証用の情報
username = ''
password = ''

# 経度・緯度情報
latArray = [35.681167] 
lonArray = [139.767052]

# 地点数回ループ
for x in range(len(latArray)):

  # エンドポイントを格納 twcservice.au-syd.mybluemix.netは認証情報のhostに相当
  weatherUrl = 'https://twcservice.au-syd.mybluemix.net/api/weather/v1/geocode/' + str(latArray[x]) + '/' + str(lonArray[x]) + '/observations.json?language=ja'

  # 本回の地点での天気情報取得
  r = requests.get(weatherUrl,auth=(username,password))

  # 結果(Unicode型)をdict型に変換
  results = json.loads(str(r.text))

  # resultsのキー(0:observation 1:metadata)
  for i in range(2):

    print('\n') 

    # 地点の番号とresultsのキーを表示
    print('"%s" position %d' % (results.keys()[i], x + 1))

    # resultsのキー(0:observation 1:metadata)に対応する各値の要素数回ループ
    for key_number in range(len(results.values()[i])):

        # resultsのあるキーに対応する値のキーとその値を順に表示
        print('%s %s' % (results.values()[i].keys()[key_number], results.values()[i][results.values()[i].keys()[key_number]]))      

実行結果(2017/01/04)

"observation" position 1
primary_wave_period None
primary_swell_direction None
terse_phrase None
expire_time_gmt 1515031200
vis 39
clds None
wx_icon 34
primary_swell_period None
min_temp 0
primary_wave_height None
uv_index 1
primary_swell_height None
precip_hrly None
uv_desc 弱い
obs_id 47662
water_temp None
pressure_desc 上昇
heat_index 6
wspd 13
rh 39
qualifier_svrty None
valid_time_gmt 1515024000
wc 3
qualifier None
blunt_phrase None
wdir 320
obs_name Tokyo
icon_extd 3400
dewPt -8
pressure 1016.6
wdir_cardinal 北西
secondary_swell_height None
key 47662
class observation
secondary_swell_period None
pressure_tend 1
temp 6
gust None
precip_total 0.0
snow_hrly None
day_ind D
secondary_swell_direction None
feels_like 3
wx_phrase 快晴
max_temp None


"metadata" position 1
language ja-JP
status_code 200
expire_time_gmt 1515031200
longitude 139.76
version 1
latitude 35.68
transaction_id 1515027125600:847700233

1: ダッシュボード(アプリ・サービス表示画面)に接続
https://console.bluemix.net/dashboard/apps

2: クリック
image.png

3: 認証情報をコード中に記載(username・password・host)
image.png

Weather Company Data For IBM Bluemix APIs
https://twcservice.mybluemix.net/rest-api/#!/twc_observations_current/v2obscurrent

Weather company Data
https://console.ng.bluemix.net/catalog/services/weather-company-data/

IBM Cloudライト・アカウント(無料・期間無制限・クレジットカード登録不要)
https://www.ibm.com/cloud-computing/jp/ja/bluemix/lite-account/

2
1
1

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
1