本帖最后由 宇longer 于 2022-2-18 20:02 编辑
腾讯云函数实现考研倒计时和金山词霸每日一句微信或Qmsg推送
更新:新增微信Server酱推送(很多人需要的,效果也非常好,感谢支持)
修改【Serverkey码】
[Python] 纯文本查看 复制代码 import requests
import json
import datetime
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
global contents
contents = ''
def sign():
#金山词霸每日一句
url = "http://open.iciba.com/dsapi/"
r = requests.get(url)
r = json.loads(r.text)
content = r["content"]
note = r["note"]
daily_sentence = content + "%0D%0A%0D%0A" + note
# 获取日期和倒计时
a = datetime.datetime.now() # 实施时间
y = str(a.year)
m = str(a.month)
d = str(a.day) # 转换为字符串,便于打印
time = y + '年' + m + '月' + d + '日' + '\n'
b = datetime.datetime(2022, 12, 25) # 自己设置的研究生考试时间
count_down = (b - a).days # 考研倒计时
count_down = '考研倒计时{}天!加油哦!'.format(count_down)
# 推送(自己添加Server酱key:https://sct.ftqq.com/)
servertalk = 'https://sctapi.ftqq.com/[Server酱key].send?title='+ count_down + '&desp=' + daily_sentence
requests.get(servertalk)
def main():
sign()
def main_handler(event, context):
return main()
if __name__ == '__main__':
main()
QQ推送【Qmsg酱】
请自行修改[ ]内的内容:
Qmsg酱官网:https://qmsg.zendee.cn/index.html
修改【qmsgkey码】
修改【qq号】
[Python] 纯文本查看 复制代码 import requests
import json
import datetime
global contents
contents = ''
def sign():
#金山词霸每日一句
url = "http://open.iciba.com/dsapi/"
r = requests.get(url)
r = json.loads(r.text)
content = r["content"]
note = r["note"]
daily_sentence = content + "\n" + note
# 获取日期和倒计时
a = datetime.datetime.now() # 实施时间
y = str(a.year)
m = str(a.month)[attach]2496093[/attach]
d = str(a.day) # 转换为字符串,便于打印
time = y + '年' + m + '月' + d + '日' + '\n'
b = datetime.datetime(2022, 12, 25) # 自己设置的研究生考试时间
count_down = (b - a).days # 考研倒计时
count_down = '考研倒计时{}天,加油哦!'.format(count_down)
# qq推送
qqtalk = 'https://qmsg.zendee.cn/send/[qmsgkey码]?msg=' +count_down+'\n' + daily_sentence + '&qq=[qq号]'
requests.get(qqtalk)
def main():
sign()
def main_handler(event, context):
return main()
if __name__ == '__main__':
main()
配置定时触发:
运行结果:
结果
|