[Python] 纯文本查看 复制代码 # 禁止转载 [url=https://www.52pojie.cn/thread-1423918-1-1.html]https://www.52pojie.cn/thread-1423918-1-1.html[/url]
import requests
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
global contents
contents = ''
# 北京
def sign():
yburl = 'https://free-api.heweather.com/s6/weather/forecast'
value = {
'location': '长沙',
'key': 'key1',
'lang': 'zh'
}
ybreq = requests.get(yburl, params=value)
ybjs = ybreq.json()
# 返回api参数:
# print(ybjs)
yb = ybjs['HeWeather6'][0]['daily_forecast']
d1 = ''
for i in range(len(yb)):
d1 =d1 + yb[i]['date'] + ' ' + yb[i]['cond_txt_d'] + ' ' + yb[i]['tmp_min'] + '—' + yb[i]['tmp_max'] + '℃' + ' ' + yb[i]['wind_dir'] + ' ' + yb[i]['wind_sc'] + '级'+'\n'
print(d1)
# #获取鸡汤
# #此处为鸡汤api地址,坛友可自行网上查询其他地址替换
# jturl = 'https://data.zhai78.com/openOneGood.php'
# jtreq = requests.get(jturl, params=value)
# jtjs = jtreq.json()
# # 返回jtapi参数:
# print(jtjs)
# jttxt = jtjs['txt']
# # qq推送
# qqtalk = 'https://qmsg.zendee.cn/send/key2?msg=【早安】@face=176@' + jttxt + '今日天气:' + d1 + '&qq=1530402404'
# requests.get(qqtalk)
# 微信推送
Wxtalk = 'https://sctapi.ftqq.com/key3.send'
NewValue = {
'text': '往后三天的天气情况:',
'desp': d1,
'lang': 'zh'
}
requests.post(Wxtalk, params=NewValue)
def main():
sign()
def main_handler(event, context):
return main()
if __name__ == '__main__':
main()
|