import os import requests import time import tkinter as tk import subprocess import threading import pyautogui import webbrowser # 设置路径 desktop_path = os.path.join(os.path.expanduser("~"), "Desktop") txt_path = os.path.join(desktop_path, "yunduanxuexi", "1.txt") # VPS配置 VPS_IP = "45.116.14.121" # ← 替换为你自己的IP VPS_FILE_URL = f"http://{VPS_IP}:2333/download" VPS_DELETE_URL = f"http://{VPS_IP}:2333/delete" # 下载1.txt函数 def download_txt(): try: r = requests.get(VPS_FILE_URL) if r.status_code == 200 and r.content.strip(): with open(txt_path, 'wb') as f: f.write(r.content) print("1.txt 下载成功") requests.get(VPS_DELETE_URL) # 删除VPS上的1.txt return True except Exception as e: print("下载失败:", e) return False # 判断1.txt是否至少两行 def txt_has_valid_data(): if os.path.exists(txt_path): with open(txt_path, 'r', encoding='utf-8') as f: lines = f.readlines() valid = len([l for l in lines if l.strip()]) >= 2 if not valid: os.remove(txt_path) print("1.txt 无效,已删除") return valid return False # ===== 自动化功能 ===== def click(x, y, wait=2): pyautogui.click(x, y) time.sleep(wait) def paste_text(text, wait=2): pyautogui.hotkey('ctrl', 'a') time.sleep(wait) pyautogui.typewrite(text) time.sleep(wait) def repeat_click(x, y, interval, count): for _ in range(count): pyautogui.click(x, y) time.sleep(interval) def run_program_A(account, password): time.sleep(3) print(f"开始账号:{account}") pyautogui.press('win') paste_text("chrome") time.sleep(3) pyautogui.press('enter') time.sleep(1) pyautogui.press('enter') time.sleep(1) pyautogui.hotkey('win', 'up') time.sleep(5) click(1496, 77, 1) paste_text("https://pc.kmelearning.com/jsncxyslhs/home/login") pyautogui.press('enter') time.sleep(2) pyautogui.press('enter') time.sleep(4) click(1583, 431, 1) paste_text(account) click(1592, 515, 1) pyautogui.typewrite(password) click(1207, 723, 1) pyautogui.moveTo(1221, 600) pyautogui.dragTo(1642, 600, duration=1) time.sleep(1) click(1417, 813, 1) time.sleep(5) for i in range(1, 5): image_name = f"{i:02}.jpg" image_path = os.path.join(desktop_path, 'yunduanxuexi', image_name) location = pyautogui.locateCenterOnScreen(image_path, confidence=0.9) if location: pyautogui.click(location) print(f"已点击图片:{image_name}") time.sleep(5) else: print(f"未找到图片:{image_name},跳过") click(1888, 31, 5) click(700, 430, 4) click(949, 631) time.sleep(1) repeat_click(949, 631, 120, 6) pyautogui.click(949, 631) click(150, 520, 3) click(700, 530, 4) click(949, 631) time.sleep(1) repeat_click(949, 631, 60, 4) pyautogui.click(949, 631) click(150, 520, 3) click(700, 630, 4) click(949, 631) time.sleep(1) repeat_click(949, 631, 120, 8) pyautogui.click(949, 631) click(150, 520, 3) pyautogui.hotkey('ctrl', 'shift', 'w') time.sleep(5) def run_yizhi(): print("运行自动学习流程...") with open(txt_path, 'r', encoding='utf-8') as f: lines = [line.strip() for line in f.readlines() if line.strip()] for i in range(0, len(lines)-1, 2): account = lines[i] password = lines[i+1] run_program_A(account, password) print("流程结束,删除本地1.txt") if os.path.exists(txt_path): os.remove(txt_path) # 每小时检测线程 def periodic_check(): while True: print("每小时检测一次 VPS ...") if download_txt() and txt_has_valid_data(): run_yizhi() else: print("无有效数据,1小时后再次检测") time.sleep(3600) # 倒计时界面(10秒) def countdown_ui(callback): def countdown_and_check(): for i in range(10, 0, -1): label_var.set(f"倒计时:{i}秒") root.update() time.sleep(1) root.destroy() callback() def cancel(): root.destroy() print("用户取消,程序不会继续") root = tk.Tk() root.title("倒计时启动") root.geometry("300x150") root.attributes('-topmost', True) label_var = tk.StringVar() tk.Label(root, textvariable=label_var, font=("Arial", 14)).pack(pady=20) tk.Button(root, text="继续", command=lambda: [root.destroy(), callback()]).pack(side="left", padx=20) tk.Button(root, text="取消", command=cancel).pack(side="right", padx=20) countdown_and_check() # 主程序入口 def main(): if os.path.exists(txt_path): os.remove(txt_path) if download_txt() and txt_has_valid_data(): def after_countdown(): run_yizhi() threading.Thread(target=periodic_check, daemon=True).start() countdown_ui(after_countdown) else: print("初始阶段未成功获取有效数据,启动后台检测线程") threading.Thread(target=periodic_check, daemon=True).start() if __name__ == '__main__': main() threading.Event().wait() # 阻塞主线程,防止程序自动退出