标签:取数 bcb day 数据 ons url restapi rest cat
函数获取使用高德天气接口
import requests
爬取数据
def read_location(name): centerurl = "https://restapi.amap.com/v3/config/district?keywords=" centerurl2 = "&subdistrict=2&key=ecbbca20adc1bcb1e1416c23a8929921" datacenter = requests.get(centerurl+name+centerurl2) ss=datacenter.json() saa = ss["districts"] center = saa[0]["center"] return center def read_locationa(code): centerurl = "https://restapi.amap.com/v3/weather/weatherInfo?key=ecbbca20adc1bcb1e1416c23a8929921&extensions=all&city=" centerurl2 = "https://restapi.amap.com/v3/weather/weatherInfo?key=ecbbca20adc1bcb1e1416c23a8929921&city=" datacenter = requests.get(centerurl+code) datacenter2 = requests.get(centerurl2+code) ss=datacenter.json() ss2 = datacenter2.json() ssaw=[] ssa2 = {} sa =ss["forecasts"][0] for it in sa[‘casts‘]: ssa = {} ssa["dayweather"] = it["dayweather"] ssa["nightweather"] = it["nightweather"] ssa["daytemp"] = it["daytemp"] ssa["nighttemp"] = it["nighttemp"] ssa["daypower"] = it["daypower"] ssa["nightpower"] = it["nightpower"] ssaw.append(ssa) ssa2["weather"]=ss2["lives"][0]["weather"] ssa2["temperature"]=ss2["lives"][0]["temperature"] ssa2["windpower"]=ss2["lives"][0]["windpower"] jun = [] for it in ssaw: jun.append(yuceday(it)) sum = 0 for it1 in jun: sum +=it1 sum = sum/4 sum +=dangday(ssa2)*2 ssa2[‘sum‘] = sum return ssa2
标签:取数 bcb day 数据 ons url restapi rest cat
原文地址:https://www.cnblogs.com/weidewozi/p/14908234.html