好友
阅读权限20
听众
最后登录1970-1-1
|
本帖最后由 milu1123 于 2022-8-26 16:12 编辑
下面代码可以提取到天气预报,不会优化,
想一对一的微信好友推送(或多人,群),定时发送,或随机1小时内发送
不是公众号的形式
有谁能帮忙在优化一下嘛??
import requests
diqu = input("请输入地区:")
head = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
}
key = '这里输入和风天气的key'
url = f'https://geoapi.qweather.com/v2/city/lookup?location={diqu}&key={key}'
resp = requests.get(url, headers=head).json()
diqu_id = resp["location"][0]["id"]
url1 = f'https://devapi.qweather.com/v7/weather/now?location={diqu_id}&key={key}'
resp1 = requests.get(url1, headers=head).json()
url2 = f'https://devapi.qweather.com/v7/indices/1d?type=1,2&location={diqu_id}&key={key}'
resp2 = requests.get(url2, headers=head).json()
url3 = f'https://devapi.qweather.com/v7/air/now?location={diqu_id}&key={key}'
resp3 = requests.get(url3, headers=head).json()
url4 = 'http://open.iciba.com/dsapi/'
resp4 = requests.get(url4, headers=head).json()
print("所在地:",resp["location"][0]["adm1"],resp["location"][0]["name"])
print('天气温度:',resp1["now"]["temp"],'℃ ',resp1["now"]["text"],"\n体感温度:",resp1["now"]["feelsLike"],"\n风向风速风力等级:",resp1["now"]["windDir"],
'',resp1["now"]["windSpeed"],'',resp1["now"]["windScale"],"\n相对湿度:",resp1["now"]["humidity"],
"\n大气压强:",resp1["now"]["pressure"],"\n空气质量:",resp3["now"]["category"],'PM2.5:',resp3["now"]["pm2p5"],"洗车指数:",resp2["daily"][1]["text"],"\n最近更新时间:", resp1["updateTime"])
print('')
print(resp4["content"])
print(resp4["note"])
|
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|