今回は天気情報を返してくれるopenweathermap.orgのAPIにアクセス
import urllib.request
import json
url = 'http://api.openweathermap.org/data/2.5/weather?q=Tokyo,jp'
response = urllib.request.urlopen(url)
content = json.loads(response.read().decode('utf8'))
print(content)
出力結果
{
"base": "stations",
"clouds": {
"all": 40
},
"cod": 200,
"coord": {
"lat": 35.69,
"lon": 139.69
},
"dt": 1439347788,
"id": 1850147,
"main": {
"humidity": 70,
"pressure": 1005,
"temp": 305.28,
"temp_max": 312.04,
"temp_min": 299.82
},
"name": "Tokyo",
"sys": {
"country": "JP",
"id": 7619,
"message": 0.014,
"sunrise": 1439323035,
"sunset": 1439372096,
"type": 1
},
"visibility": 10000,
"weather": [
{
"description": "scattered clouds",
"icon": "03d",
"id": 802,
"main": "Clouds"
}
],
"wind": {
"deg": 110,
"speed": 2.6
}
}