Scheduler任务调度模块自动发送微信消息

 

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# __author__ =
# pip install wxauto
# pip install schedule
# pip install itchat 该模块已不能使用

"""
import schedule
import time

def job():
    print("我在这里工作...")

schedule提供了多种调度选项,包括:
schedule.every().day.at("HH:MM").do(job)  – 每天特定时间
schedule.every().hour.do(job)   – 每小时执行一次
schedule.every().minute.do(job)  – 每分钟执行一次
schedule.every().second.do(job)  – 每秒执行一次
schedule.every().monday.do(job)  – 每周一执行一次
schedule.every().wednesday.at("HH:MM").do(job)  – 每周三特定时间执行一次

while True:
    # 运行所有安排好的任务
    schedule.run_pending()
    # 每隔一秒检查一次
    time.sleep(1)
"""

"""
import itchat

def lcb():
    print("登录完成!")

def ecb():
    print("退出成功!")

# 登录到微信
# hotReload=True 表示保持登录状态,这样下次运行时就不需要重新扫码了
itchat.auto_login(hotReload=True, loginCallback=lcb, exitCallback=ecb)  # 扫描二维码登录,首次需要手动操作

# 获取好友列表
friends = itchat.get_friends()

# 根据昵称找到具体的好友
friend = itchat.search_friends(name='张三')  # 替换为你的好友的昵称
if friend:
    itchat.send('你好!这是一条自动发送的消息。', toUserName=friend[0]['UserName'])  # 发送消息
else:
    print("未找到该好友。")

# 退出登录
itchat.logout()
"""


from wxauto import WeChat
import schedule
import time

to = "文件传输助手"  # 备注名
file = "测试附件.xlsx"  # 要发送的文件
msg = "今天的日报请查收:"  # 要发送的消息
wx = WeChat()  # 获取当前微信客户端

def job():
    time.sleep(3)  # 等待3秒
    wx.ChatWith(to)  # 打开聊天窗口
    wx.SendMsg(msg)  # 发送消息
    wx.SendFiles(file)  # 发送文件
    print("发送结束!")

# 定时任务,每10秒发一次消息
schedule.every(10).seconds.do(job)

while True:
    # 运行所有安排好的任务
    schedule.run_pending()
    # 每隔一秒检查一次
    time.sleep(1)

 相关链接:
     https://gitcode.com/gh_mirrors/py/pycron
     https://blog.csdn.net/freeking101/article/details/119822382       # crontab、apscheduler、schedule、sched2
     https://cloud.tencent.com/developer/article/2312428        # Python APScheduler库
     https://apscheduler.readthedocs.io/en/latest/userguide.html
     https://www.cnblogs.com/ningningqi/p/18085030      # python APScheduler任务调度库,相当于Linux定时任务
     https://www.cnblogs.com/luohenyueji/p/16993259.html    # PyAutoGUI使用教程
     https://zhuanlan.zhihu.com/p/718728254    # 使用selenium库操作浏览器
     https://github.com/mozilla/geckodriver/releases    # Firefox驱动下载
     https://mirrors.huaweicloud.com/chromedriver/    # chrome驱动下载
     https://developer.chrome.com/docs/chromedriver/downloads?hl=zh-cn    # chrome驱动下载
     https://learn.microsoft.com/zh-cn/microsoft-edge/webdriver/?tabs=c-sharp    # 使用WebDriver自动执行Microsoft Edge
     https://www.kancloud.cn/gnefnuy/pywinauto_doc/1193035         # pywinauto库
     https://www.cnblogs.com/xiangfeigao/p/18245784                      # 使用pywinauto库操作微信

posted @ 2025-02-07 14:00  風£飛  阅读(64)  评论(0)    收藏  举报