今回はRequestsをつかって、Python経由でOpenWeatherMapから天気情報取得します。
OpenWeatherMapについては、前回の記事を参照してください。
shuzo-kino.hateblo.jp
実際のところ
すでにAPIKEYをとっているものとします。
import requests yourappkey = {{YOURAPPKEY}} url = 'http://api.openweathermap.org/data/2.5/weather?id=1850147&appid={0}'.format(yourappkey) r = requests.get() r.text """ '{"coord":{"lon":139.69,"lat":35.69},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":279.58,"pressure":1016,"humidity":41,"temp_min":277.15,"temp_max":281.15},"visibility":16093,"wind":{"speed":6.7,"deg":30},"clouds":{"all":1},"dt":1518699480,"sys":{"type":1,"id":7622,"message":0.0106,"country":"JP","sunrise":1518643686,"sunset":1518682985},"id":1850147,"name":"Tokyo","cod":200}' """