Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save WebSamuraiDaisuke/8c98872b41f1858819a32b6b05c60870 to your computer and use it in GitHub Desktop.
Save WebSamuraiDaisuke/8c98872b41f1858819a32b6b05c60870 to your computer and use it in GitHub Desktop.
Livedoor Weather API 天気予報APIを軽くたたいてみた
import urllib.request
import json
location = u'080020' #場所
url = 'http://weather.livedoor.com/forecast/webservice/json/v1?city=%s' %location
html = urllib.request.urlopen(url)
jsonfile = json.loads(html.read().decode('utf-8'))
print('***********')
print(jsonfile['pinpointLocations'][0]['name'])
print(jsonfile['forecasts'][0]['telop'])
#jsonfileでロードしてきた情報はType:Noneなので、str()で変換が必要
temp = str(jsonfile['forecasts'][0]['temperature']['max'])
if temp == u'None':
print('気温情報はありません')
else:
print('最高気温:' + str(jsonfile['forecasts'][0]['temperature']['max']['celsius']+'度'))
print('***********')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment