码迷,mamicode.com
首页 > 其他好文 > 详细

天气情况的获取

时间:2021-06-21 20:05:25      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:取数   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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!