首页 > 其他 > 详细

天气情况的获取

时间:2021-06-20 23:01:31      阅读:24      评论:0      收藏:0      [点我收藏+]

函数获取使用高德天气接口

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

 

天气情况的获取

原文:https://www.cnblogs.com/weidewozi/p/14908234.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!