返回顶部

企业微信,python机器人定时发送信息

# -*- coding: utf-8 -*-
import time
import schedule
import requests


url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=3be1e100-2860-4bc6-9169-xxxxxxxxxxxxxxxxx'
# 当前时间为
load_time = time.strftime('%Y-%m-%d %H:%M:%S')

def morning():
    data = {
        'msgtype': 'text',
        'text': {'content': f'早上好, 当前时间为:{load_time} \n记得打上班卡哈'}
    }
    requests.post(url, json=data)


def evening():
    data = {
        'msgtype': 'text',
        'text': {'content': f'上班一天辛苦了哈, 当前时间为:{load_time} \n记得打下班卡哈'}
    }
    requests.post(url, json=data)


# 每天的指定时间执行
schedule.every().day.at('23:50').do(morning)
schedule.every().day.at('23:51').do(evening)
# 10分钟执行一次
schedule.every(10).minutes.do(morning)
schedule.every(10).minutes.do(evening)
# 每隔5天到10天执行一次
schedule.every(5).to(10).days.at('00:00').do(morning)
schedule.every(5).to(10).days.at('00:00').do(evening)
# 每周一的这个时候执行一次任务
schedule.every().monday.do(morning)
# 每周三00:03执行一次任务
schedule.every().wednesday.at('00:03').do(morning)

while True:
    # 运行所有可以运行的任务
    schedule.run_pending()
    print(load_time)
    time.sleep(1)

 

posted @ 2022-09-28 15:09  gz_zyg  阅读(336)  评论(0编辑  收藏  举报