我只弄出来当时的天气
import requests
import json
url = "https://api.openweathermap.org/data/2.5/onecall?"
loc = "lat=39.72668&lon=116.34149"
unit ="&units=metric"
lang ="&lang=ja"
excl = "&exclude=minutely,hourly,daily"
key ="&appid=8ab0436dace537dcfce0101f5f0f234f"
res=requests.get(url+loc+unit+lang+excl+key)
res_j = res.json()
with open("current.json","w") as f:
json.dump(res_j,f)
import json
import pprint as pp
with open("current.json") as f:
data = json.load(f)
print("Length of data =",len(data))
print()
print("Key = ",data.keys())
for key in data.keys():
item = data[key]
print(key,"=",end="")
pp.pprint(data[key])
print()
代码中参数excl是排除了一些数据,将参数中的excl改成“”,获取的数据就多了,若只要按小时数据,写成:excl = "&exclude=minutely,daily"