本帖最后由 zllebron3wade 于 2021-4-22 15:53 编辑
看到这位大佬发的帖子。https://www.52pojie.cn/thread-1423918-1-1.html
我看了下开发文档,说和风天气老的api s6支持到2021年年底,所以更新了一波代码。感谢这位大佬
[Asm] 纯文本查看 复制代码 [color=#878a85][backcolor=rgb(27, 36, 38)][font=Consolas, "]# 禁止转载 [url=https://www.52pojie.cn/thread-1423918-1-1.html]https://www.52pojie.cn/thread-1423918-1-1.html[/url][/font][/backcolor][/color]
import requests
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
global contents
contents = ''
# 北京
def sign():
yburl2 = 'https://devapi.qweather.com/v7/weather/3d?'
value2 = {
'location': '121.54,29.81', #所在地区的经度和维度
'key': 'key',
'lang': 'zh'
}
ybreq2 = requests.get(yburl2, params=value2)
ybjs2 = ybreq2.json()
# 返回api参数:
print(ybjs2)
for i in range(2):
yb = ybjs2['daily']
d1 = yb[i]['fxDate'] + ' ' + yb[i]['textDay'] + ' ' + yb[i]['tempMin'] + '—' + yb[i]['tempMax'] + '℃' + ' ' + \
yb[i]['windDirDay'] + ' ' + yb[i]['windScaleDay'] + '级'
qqtalk = 'https://qmsg.zendee.cn/send/key?msg=' + d1 + '&qq=自己qq号'
requests.get(qqtalk)
def main():
sign()
def main_handler(event, context):
return main()
if __name__ == '__main__':
main() |