import urequests
def weather(key,city):
url="http://api.seniverse.com/v3/weather/now.json?key=%s&location=%s&language=zh-Hans&unit=c" % (key,city)
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE' }
ba=[]
print(url)
re=urequests.get(url,headers=headers)
my=re.json()
weather_status=["晴","晴","晴","晴","多云","晴间多云","晴间多云","大部多云","大部多云","阴","阵雨","雷阵雨","雷阵雨伴有冰雹","小雨","中雨","大雨","暴雨","大暴雨","特大暴雨","冻雨","雨夹雪","阵雪","小雪","中雪","大雪","暴雪","浮尘","扬沙","沙尘暴","强沙尘暴","雾","霾","风","大风","飓风","热带风暴","龙卷风","冷","热","未知"]
code=my['results'][0]['now']['code']#天气代码
tep=my['results'][0]['now']['temperature']#温度
return [tep,code,weather_status[int(code)]]
key="私钥"
#参数key,城市拼音
weather(key,"suzhou")
心知天气API使用
发表评论