png
py文件
import os
import pyautogui
import time
from typing import Callable, Tuple
from datetime import datetime
import cv2
import schedule
#通过图像模板匹配在屏幕上找到指定区域并操作
def imgAutoClick(tempFile: str, whatDo: Callable[[Tuple[int, int, int, int]], None], debug: bool = False):
#截图
screenshot_path = 'big.png'
pyautogui.screenshot(screenshot_path)
#加载和处理图像
gray = cv2.imread(screenshot_path, cv2.IMREAD_GRAYSCALE)
img_template = cv2.imread(tempFile, cv2.IMREAD_GRAYSCALE)
#获取模板尺寸
w, h = img_template.shape[::-1]
#模板匹配
res = cv2.matchTemplate(gray, img_template, cv2.TM_SQDIFF)
min_val, _, min_loc, _ = cv2.minMaxLoc(res)
#计算边界框坐标
top_left = min_loc
bottom_right = (top_left[0] + w, top_left[1] + h)
#移动鼠标并执行操作
pyautogui.moveTo(top_left[0] + w / 2, top_left[1] + h / 2)
whatDo((top_left[0], top_left[1], w, h))
#调试
if debug:
img = cv2.imread(screenshot_path)
cv2.rectangle(img, top_left, bottom_right, (0, 0, 255), 2)
img_resized = cv2.resize(img, (0, 0), fx=0.5, fy=0.5, interpolation=cv2.INTER_NEAREST)
cv2.imshow("Processed", img_resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
#清理截图
os.remove(screenshot_path)
#登录会议
def signIn(meeting_id):
#会议路径
os.startfile(r"xxxxxxxx")
time.sleep(10)
#会议图标
imgAutoClick("xxxxtubiao.png", pyautogui.click, False)
time.sleep(1)
#加入会议
imgAutoClick("xxxxjoinbtn.png", pyautogui.click, False)
time.sleep(1)
#输入会议号
imgAutoClick("xxxxmeeting_id.png", pyautogui.click, False)
pyautogui.write(meeting_id)
time.sleep(2)
#最后加入会议
imgAutoClick("xxxxxfinal.png", pyautogui.click, False)
time.sleep(1)
#再次登录会议
def signIn_two(meeting_id):
#加入会议
imgAutoClick("xxxxxxjoinbtn.png", pyautogui.click, False)
time.sleep(1)
#输入会议号
imgAutoClick("xxxxxmeeting_id.png", pyautogui.click, False)
pyautogui.write(meeting_id)
time.sleep(2)
#最后加入会议
imgAutoClick("xxxxxfinal.png", pyautogui.click, False)
time.sleep(1)
def job():
while True:
#获取当前时间
now = datetime.now()
#判断是否是周六
if now.weekday() == 5:
#开始时间
start_time = datetime(now.year, now.month, now.day, 14, 0, 0).strftime("%H:%M:%S")
#结束时间
end_time = datetime(now.year, now.month, now.day, 17, 30, 0).strftime("%H:%M:%S")
#当前时间
current = now.strftime("%H:%M:%S")
#会议号
meeting_id = '111-111-111'
#间隔一小时进行操作
if start_time <= current <= end_time:
if current == "14:00:00":
signIn(meeting_id)
time.sleep(5)
elif current == "15:00:00":
signIn_two(meeting_id)
time.sleep(5)
elif current == "16:00:00":
signIn_two(meeting_id)
time.sleep(5)
elif current == "17:00:00":
signIn_two(meeting_id)
time.sleep(5)
else:
print("Today is not Saturday.")
break
if __name__ == '__main__':
#设置定时任务
schedule.every().saturday.at("13:58").do(job)
while True:
schedule.run_pending()
time.sleep(1)
bat文件
@echo off
输出当前工作目录
echo Current directory: %cd%
输出Python 解释器的路径
echo Python path: "xxxxx.exe"
输出py脚本的路径
echo Script path: "xxxxx.py"
执行指定的 py脚本
"xxxxx.exe" "xxxxx.py"
pause
vbs
在后台最小化命令提示符窗口并执行批处理文件
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "xxxxxxx.bat" & Chr(34), 7
py1文件 :增加图形化窗口
import os
import pyautogui
import time
from typing import Callable, Tuple
from datetime import datetime
import cv2
import schedule
import tkinter as tk
from tkinter import messagebox
#通过图像模板匹配在屏幕上找到指定区域并操作
def imgAutoClick(tempFile: str, whatDo: Callable[[Tuple[int, int, int, int]], None], debug: bool = False):
#截图
screenshot_path = 'big.png'
pyautogui.screenshot(screenshot_path)
#加载和处理图像
gray = cv2.imread(screenshot_path, cv2.IMREAD_GRAYSCALE)
img_template = cv2.imread(tempFile, cv2.IMREAD_GRAYSCALE)
#获取模板尺寸
w, h = img_template.shape[::-1]
#模板匹配
res = cv2.matchTemplate(gray, img_template, cv2.TM_SQDIFF)
min_val, _, min_loc, _ = cv2.minMaxLoc(res)
#计算边界框坐标
top_left = min_loc
bottom_right = (top_left[0] + w, top_left[1] + h)
#移动鼠标并执行操作
pyautogui.moveTo(top_left[0] + w / 2, top_left[1] + h / 2)
whatDo((top_left[0], top_left[1], w, h))
#调试
if debug:
img = cv2.imread(screenshot_path)
cv2.rectangle(img, top_left, bottom_right, (0, 0, 255), 2)
img_resized = cv2.resize(img, (0, 0), fx=0.5, fy=0.5, interpolation=cv2.INTER_NEAREST)
cv2.imshow("Processed", img_resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
#清理截图
os.remove(screenshot_path)
#登录会议
def signIn(meeting_id):
#会议路径
os.startfile(r"xxxxxxxx")
time.sleep(10)
#会议图标
imgAutoClick("xxxxtubiao.png", pyautogui.click, False)
time.sleep(1)
#加入会议
imgAutoClick("xxxxjoinbtn.png", pyautogui.click, False)
time.sleep(1)
#输入会议号
imgAutoClick("xxxxmeeting_id.png", pyautogui.click, False)
pyautogui.write(meeting_id)
time.sleep(2)
#最后加入会议
imgAutoClick("xxxxxfinal.png", pyautogui.click, False)
time.sleep(1)
#再次登录会议
def signIn_two(meeting_id):
#加入会议
imgAutoClick("xxxxxxjoinbtn.png", pyautogui.click, False)
time.sleep(1)
#输入会议号
imgAutoClick("xxxxxmeeting_id.png", pyautogui.click, False)
pyautogui.write(meeting_id)
time.sleep(2)
#最后加入会议
imgAutoClick("xxxxxfinal.png", pyautogui.click, False)
time.sleep(1)
def job(meeting_id):
while True:
#获取当前时间
now = datetime.now()
#判断是否是周六
if now.weekday() == 5:
#开始时间
start_time = datetime(now.year, now.month, now.day, 14, 0, 0).strftime("%H:%M:%S")
#结束时间
end_time = datetime(now.year, now.month, now.day, 17, 30, 0).strftime("%H:%M:%S")
#当前时间
current = now.strftime("%H:%M:%S")
#间隔一小时进行操作
if start_time <= current <= end_time:
if current == "14:00:00":
signIn(meeting_id)
time.sleep(5)
elif current == "15:00:00":
signIn_two(meeting_id)
time.sleep(5)
elif current == "16:00:00":
signIn_two(meeting_id)
time.sleep(5)
elif current == "17:00:00":
signIn_two(meeting_id)
time.sleep(5)
def start_automation():
meeting_id = entry.get().strip()
meeting_id = meeting_id.replace('-', '').replace(' ','')
if meeting_id.isdigit() and len(meeting_id) in range(9,13):
#设置定时任务
schedule.every().saturday.at("13:58").do(job,meeting_id)
messagebox.showinfo("自动化启动", "自动化任务已启动")
while True:
schedule.run_pending()
time.sleep(1)
else:
messagebox.showwarning("输入错误", "请输入有效的会议号。")
if __name__ == '__main__':
# 创建主窗口
root = tk.Tk()
root.title("会议自动化工具")
# 设置窗口大小
root.geometry("330x180")
root.resizable(False, False)
# 创建标签
label = tk.Label(root, text="请输入会议号:")
label.pack(pady=10)
# 创建文本输入框
entry = tk.Entry(root, width=30)
entry.pack(pady=5)
# 创建按钮
button = tk.Button(root, text="启动自动化", command=start_automation)
button.pack(pady=20)
# 运行主循环
root.mainloop()
运行截图: