腾讯云函数实现【考研倒计时】和金山词霸每日一句微信&Qmsg推送
本帖最后由 宇longer 于 2022-2-18 20:02 编辑腾讯云函数实现考研倒计时和金山词霸每日一句微信或Qmsg推送
更新:新增微信Server酱推送(很多人需要的{:1_918:},效果也非常好,感谢支持)
修改【Serverkey码】
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/.send?title='+ count_down + '&desp=' + daily_sentence
requests.get(servertalk)
def main():
sign()
def main_handler(event, context):
return main()
if __name__ == '__main__':
main()
https://static.52pojie.cn/static/image/hrline/1.gif
QQ推送【Qmsg酱】
请自行修改[ ]内的内容:
Qmsg酱官网:https://qmsg.zendee.cn/index.html
修改【qmsgkey码】
修改【qq号】
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)
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/?msg=' +count_down+'\n' + daily_sentence + '&qq='
requests.get(qqtalk)
def main():
sign()
def main_handler(event, context):
return main()
if __name__ == '__main__':
main()
配置定时触发:
运行结果:
{
"errorCode": 1,
"errorMessage": "Traceback (most recent call last):\nFile \"/var/runtime/python37/bootstrap.py\", line 133, in init_handler\n func_handler = get_func_handler(file.rsplit(\".\", 1), func)\nFile \"/var/runtime/python37/bootstrap.py\", line 159, in get_func_handler\n mod = imp.load_module(mname, *imp.find_module(mname))\nFile \"/var/lang/python37/lib/python3.7/imp.py\", line 234, in load_module\n return load_source(name, filename, file)\nFile \"/var/lang/python37/lib/python3.7/imp.py\", line 171, in load_source\n module = _load(spec)\nFile \"Ϗrozen; importlib._bootstrap>\", line 696, in _load\nFile \"Ϗrozen; importlib._bootstrap>\", line 677, in _load_unlocked\nFile \"Ϗrozen; importlib._bootstrap_external>\", line 724, in exec_module\nFile \"Ϗrozen; importlib._bootstrap_external>\", line 860, in get_code\nFile \"Ϗrozen; importlib._bootstrap_external>\", line 791, in source_to_code\nFile \"Ϗrozen; importlib._bootstrap>\", line 219, in _call_with_frames_removed\nFile \"/var/user/index.py\", line 1\n <span;>import; requests\n ^\nSyntaxError: invalid syntax",
"requestId": "3f08f4b5-fce4-45e2-8cda-57701e38e5a8",
"statusCode": 443
} 宇longer 发表于 2022-2-27 11:22
[]这个符号肯定要去掉啊,这是url链接呢可能我没讲清楚
去了还是{"errorCode":1,"errorMessage":"Traceback (most recent call last):\nFile \"/var/runtime/python37/bootstrap.py\", line 133, in init_handler\n func_handler = get_func_handler(file.rsplit(\".\", 1), func)\nFile \"/var/runtime/python37/bootstrap.py\", line 159, in get_func_handler\n mod = imp.load_module(mname, *imp.find_module(mname))\nFile \"/var/lang/python37/lib/python3.7/imp.py\", line 234, in load_module\n return load_source(name, filename, file)\nFile \"/var/lang/python37/lib/python3.7/imp.py\", line 171, in load_source\n module = _load(spec)\nFile \"Ϗrozen; importlib._bootstrap>\", line 696, in _load\nFile \"Ϗrozen; importlib._bootstrap>\", line 677, in _load_unlocked\nFile \"Ϗrozen; importlib._bootstrap_external>\", line 728, in exec_module\nFile \"Ϗrozen; importlib._bootstrap>\", line 219, in _call_with_frames_removed\nFile \"/var/user/index.py\", line 1, in <module;>\n import requests\nModuleNotFoundError: No module named 'requests'","requestId":"0903ec30-10b0-43ea-a127-451e088a7fc0","statusCode":443} 没有教程吗 你是我的人 发表于 2021-5-10 13:15
没有教程吗
个人认为太简单了 还没用过云函数呢 这个是不是不能推送图片啊?我试了 好像推送的图片的链接 确实简单 实在不会可以百度下 百度都有教程 这个接口收下了。
这个可以,感谢 整了好久,函数执行成功,却收不到消息,不整了:'(weeqw 感谢楼主分享