Created
July 16, 2017 12:00
-
-
Save WebSamuraiDaisuke/8c98872b41f1858819a32b6b05c60870 to your computer and use it in GitHub Desktop.
Livedoor Weather API 天気予報APIを軽くたたいてみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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