实现需求:
Python定时发送微信消息
import pyautogui as pg
import pyperclip as pc
from apscheduler.schedulers.blocking import BlockingScheduler
"""
实现定时自动发送消息
"""
# 操作间隔为1秒
pg.PAUSE = 1
name = 'Hello~'
msg = '是时候点餐啦!!'
def main():
# 打开微信
pg.hotkey('ctrl', 'alt', 'w')
pg.hotkey('ctrl', 'f')
# 找人
pc.copy(name)
pg.hotkey('ctrl', 'v')
pg.press('enter')
# 发送消息
pc.copy(msg)
pg.hotkey('ctrl', 'v')
pg.press('enter')
# 隐藏微信
pg.hotkey('ctrl', 'alt', 'w')
if __name__ == '__main__':
scheduler = BlockingScheduler() # 实例化一个调度器
scheduler.add_job(main, 'cron', hour=8, minute=0) # 添加任务
scheduler.start()
运行结果
仅用于学习,勿用于刷屏!!