import pandas as pd
import schedule
import time
import pyautogui
import os
import pyperclip
# 定义打开Excel文件函数
def read_excel(file_path):
data = pd.read_excel(file_path)
return data
# 定义微信发送消息函数
def job(msg,who):
# 打开微信
os.system("start weixin:")
time.sleep(0.5)
# 第一次查找文件传输助手
pyautogui.hotkey("Ctrl","f")
time.sleep(0.5)
pyperclip.copy('文件传输助手')
pyautogui.hotkey('ctrl', 'v')
time.sleep(0.5)
pyautogui.press('enter')
time.sleep(0.5)
# 第二次查找目标
pyautogui.hotkey("Ctrl","f")
time.sleep(0.5)
pyperclip.copy(who)
pyautogui.hotkey('ctrl', 'v')
time.sleep(0.5)
pyautogui.press('enter')
time.sleep(0.5)
pyperclip.copy(msg)
pyautogui.hotkey('ctrl', 'v')
time.sleep(0.5)
pyautogui.press('enter')
time.sleep(0.5)
# 关闭微信窗口
pyautogui.hotkey("Alt","F4")
# 定义定时任务函数
def tasks(data):
for index,row in data.iterrows():
send_time = row['Time']
who = row['Object']
msg = row['Task']
schedule.every().day.at(str(send_time)).do(job,msg,who)
# 查找当前文件夹.xlsx文件
path = os.getcwd()
files = os.listdir(path)
excelfiles = [f for f in os.listdir('.') if not f.startswith("~$") and f.endswith(".xlsx")]
fullpath = os.path.join(path,excelfiles[0])
# 读取Excel模板数据
excel_data = read_excel(fullpath)
# 执行定时任务
tasks(excel_data)
# 持续运行待处理任务
while True:
schedule.run_pending()
time.sleep(1)