需求:
由于工作中需要每天写日报,但有时候会忘记,需要定时在企业微信群里提醒(工作日周一到周五每天下班前提醒)
代码:
import json
import schedule
import requests
def send_markdown(webhook, content):
register_data = {
"msgtype": "markdown", # 支持文本(text)、markdown(markdown)、图片(image)、图文(news)四种消息类型
"markdown": {
"content": "%s" % content
}
}
response = requests.post(url=webhook, json=register_data)
print (response.json())
print("send message sucess..")
def main():
webhook = "自己创建的群连接"
content = "@all,日报填写时间"
send_markdown(webhook, content)
if __name__ == "__main__":
send_time = "18:00"
schedule.every().monday.at(send_time).do(main)
schedule.every().tuesday.at(send_time).do(main)
schedule.every().wednesday.at(send_time).do(main)
schedule.every().thursday.at(send_time).do(main)
schedule.every().friday.at(send_time).do(main)
print("定时提醒任务执行中..工作日每天%s进行提醒"%send_time)
while True:
try:
schedule.run_pending()
time.sleep(1)
except Exception as e:
print('异常:', e)
执行:

测试结果:



本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 sumchina520@foxmail.com 举报,一经查实,本站将立刻删除。
如若转载,请注明出处:https://www.yiheng8.com/162794.html
如若转载,请注明出处:https://www.yiheng8.com/162794.html