Python3で天気を取得するツールを作ってみます
使うライブラリ・環境は以下の通り
import click import json import requests @click.command() @click.option('--id', default='1850147', help='Number of greetings.') def hello(id): yourappid = '{{YOUR API KEY}}' string = 'http://api.openweathermap.org/data/2.5/weather?id={0}&appid={1}'.format(id,yourappid) r = requests.get(string) d = json.loads(r.text) weather = d['weather'][0]['description'] tempture = d['main']['temp'] result = "Weather:{0}. Tempture:{1}".format(weather, tempture) click.echo(result) """ ex) 'Weather:clear sky. Tempture:279.58' """ if __name__ == '__main__': hello()