现在,我只能请求当前时间的天气。但是,我想请求当前天气和之后每小时的天气。
像这样
要查找当前天气,我使用了https://openweathermap.org/current,但我尝试使用https://openweathermap.org/api/hourly-forecast获取每小时数据,但是当我查看示例 .json 时,我无法弄清楚如何更改时间以获取当时的天气。
这是我如何获取当前天气数据的示例:
combined = city + ',' + country
weatherkey = '****'
url = 'https://api.openweathermap.org/data/2.5/weather'
params = {'APPID' : weatherkey, 'q' : combined, 'units' : 'metric'}
response = requests.get(url, params = params)
weather = response.json()
desc = string.capwords(str(weather['weather'][0]['description']))
temp = str(round(weather['main']['temp'], 1)) + '°C'
print(desc)
print(temp)
谢谢