diff --git a/main.py b/main.py index 84a3567..3b7fc4e 100644 --- a/main.py +++ b/main.py @@ -43,11 +43,18 @@ user32 = ctypes.windll.user32 root_plugin_dir = os.path.join(os.getcwd(), 'proxy_auth_plugin') -# 初始化数据库 +proxy_manager = ProxyManagerSQLite(db_path="proxies.db") db_manager = AccountManagerSQLite(db_path="accounts.db") -proxy_manager = ProxyManagerSQLite() -proxy_manager.import_proxies_with_classifier("IP.txt", classifier=classifier_smartproxy) +proxy_manager.import_proxies_with_classifier( "Ip.txt",classifier=classifier_smartproxy) + + +def init_worker(): + global proxy_manager, db_manager + # 在每个子进程中初始化数据库管理器 + proxy_manager = ProxyManagerSQLite(db_path="proxies.db") + db_manager = AccountManagerSQLite(db_path="accounts.db") + # 全局写入锁 write_lock = multiprocessing.Lock() @@ -274,14 +281,15 @@ def click_the_login_button(tab, login_a): tab.get(href) -def input_email(tab, hwnd, email, email_input): - email_input.clear() +def input_email(tab, hwnd, email, email_input, max_retries=3): """ - 输入账号并点击“下一步”按钮 + 输入账号并点击“下一步”按钮。如果两次尝试都未成功,退出。 :param tab: 浏览器对象 :param email: 用户的邮箱账号 + :param email_input: 输入框对象 + :param max_retries: 最大尝试次数 """ - # 定位邮箱输入框 + email_input.clear() # 模拟人类输入,每次输入一个字符,并随机延迟 for char in email: @@ -302,14 +310,29 @@ def input_email(tab, hwnd, email, email_input): tab.wait(2) - simulate_mouse(hwnd, 600, 600) + retry_count = 0 + while retry_count < max_retries: + # 模拟点击操作 + simulate_mouse(hwnd, 650, 650) - tab.wait.load_start() + # 等待页面加载开始 + tab.wait.load_start() - flag = tab.wait.ele_deleted(next_input) - if not flag: - next_input.set.style('width', '10px') - next_input.set.style('height', '10px') + # 等待7秒,看按钮是否消失 + flag = tab.wait.ele_deleted(next_input, timeout=7) + if flag: + print(f"第 {retry_count + 1} 次尝试成功,按钮已消失。") + return True + else: + retry_count += 1 # 增加尝试次数 + print(f"第 {retry_count} 次尝试失败,按钮未消失,重新尝试...") + + if retry_count >= max_retries: + # 两次尝试都失败,调整按钮大小为10px + next_input.set.style('width', '10px') + next_input.set.style('height', '10px') + print(f"尝试 {max_retries} 次仍未成功,调整按钮大小并退出。") + return False # 超过最大尝试次数后退出函数 # 点击重试按钮 @@ -317,7 +340,7 @@ def recover(tab, recover_a): recover_a.click(by_js=True) -def input_password(tab, hwnd, password, password_input): +def input_password(tab, hwnd, password, password_input, max_retries=2): password_input.clear() """ 输入密码并点击“下一步”按钮 @@ -342,14 +365,44 @@ def input_password(tab, hwnd, password, password_input): next_input.set.style('height', '1000px') tab.wait(2) - simulate_mouse(hwnd, 700, 700) + retry_count = 0 + while retry_count < max_retries: + # 模拟点击操作 + simulate_mouse(hwnd, 700, 700) + + # 等待页面加载开始 + tab.wait.load_start() + + # 等待7秒,看按钮是否消失 + flag = tab.wait.ele_deleted(next_input, timeout=7) + if flag: + print(f"第 {retry_count + 1} 次尝试成功,按钮已消失。") + break # 按钮成功消失,跳出循环 + else: + # 获取页面提示信息 + text = "" + try: + text = tab.ele('@aria-live=polite', timeout=1).text + except Exception as e: + print("获取页面提示失败:", e) + + print(f"页面提示: {text}") + + if text == "": + retry_count += 1 + print(f"页面提示为空,第 {retry_count} 次尝试失败,重新尝试...") + else: + print(f"页面提示不为空:{text}, 不进行重试,退出。") + break # 页面提示不为空,退出重试流程 + + if retry_count >= max_retries: + # 两次尝试都失败,调整按钮大小为10px + next_input.set.style('width', '10px') + next_input.set.style('height', '10px') + print(f"尝试 {max_retries} 次仍未成功,调整按钮大小并退出。") + return False # 超过最大尝试次数后退出函数 - tab.wait.load_start() - flag = tab.wait.ele_deleted(next_input, timeout=10) - if not flag: - next_input.set.style('width', '10px') - next_input.set.style('height', '10px') def click_alternate_email_verification_button(tab, email_div): @@ -396,14 +449,14 @@ def click_use_other_account_button2(tab, next_span): # 修改辅助邮箱账号 def modify_the_secondary_email1(tab, auxiliary_email_account): - # button = tab.ele('@@tag()=i@@text()=edit', timeout=15) - # button.click(by_js=True) - # tab.wait(2) - # input = tab.ele('@type=email', timeout=15) - # input.clear() - # for char in auxiliary_email_account: - # input.input(char) # Enter one character at a time - # tab.wait(random.uniform(0.1, 0.3)) # Random delay between 0.1 and 0.3 seconds + button = tab.ele('@@tag()=i@@text()=edit', timeout=15) + button.click(by_js=True) + tab.wait(2) + input = tab.ele('@type=email', timeout=15) + input.clear() + for char in auxiliary_email_account: + input.input(char) # Enter one character at a time + tab.wait(random.uniform(0.1, 0.3)) # Random delay between 0.1 and 0.3 seconds # 点击保存 save_span = tab.ele('@text()=Save', timeout=15) @@ -560,8 +613,6 @@ def update_status_in_db(email: str, status: str): """ 更新数据库中指定账户的状态。 """ - db_manager = AccountManagerSQLite(db_path="accounts.db") - # 更新数据库中对应账户的状态 db_manager.update_record(email=email, change_status=status) @@ -649,8 +700,8 @@ def logutGoogle(tab) -> bool: return False # 无用分支,不过为了避免函数太长回头修改时候忘记,还是写个 False 以防万一 -def main(email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, proxy_username, proxy_password,region, row_index): - +def main(email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, proxy_username, proxy_password,region): + update_status_in_db(email_account, '开始处理,没有改好') print("邮箱账户:", email_account) # 邮箱账户 print("邮箱密码:", email_password) # 邮箱密码 @@ -662,11 +713,12 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re print("代理用户名:", proxy_username) # 代理用户名 print("代理密码:", proxy_password) # 代理密码 print("代理区域:", region) - print("行索引:", row_index) # 行索引 global browser, plugin_path, user_dir, attempt # 生成一个 6 位的随机数 global random_number + + try: random_number = str(random.randint(100000000, 999999999)) """ @@ -683,6 +735,12 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re print("任务被强制停止,退出主函数") return None # 直接返回 None,跳过当前任务 + if not proxy_host: + save_log(random_number, f"没有{region}区域的代理") + update_status_in_db(email_account, f"没有{region}区域代理") + return False + + lock = FileLock("proxy_auth_extension.lock") with lock: # 加锁,确保其他进程在解锁前无法操作 @@ -758,11 +816,11 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re flag = tab.get('https://workspace.google.com/intl/zh-CN/gmail/') save_log(random_number, f"访问谷歌邮箱页面的状态:{flag}") if not flag: - browser.quit() + update_status_in_db(email_account, "无法访问谷歌邮箱页面,请重试") return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) save_log(random_number, "已经访问谷歌页面") @@ -806,16 +864,23 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re if hwnd is None: print("无法找到窗口句柄") save_log(random_number, "无法找到窗口句柄") + update_status_in_db(email_account, '无法找到窗口句柄') return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) try: # 输入邮箱账号 email_input = tab.ele('@aria-label=电子邮件地址或电话号码', timeout=15) if email_input: - input_email(tab, hwnd, email_account, email_input) # 使用传入的邮箱账号 + flag = input_email(tab, hwnd, email_account, email_input) # 使用传入的邮箱账号 + if not flag: + update_status_in_db(random_number, "输入完邮箱后点击下一步出错") + return ( + email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, + proxy_port, + proxy_username, proxy_password, region) random_sleep(tab) except ElementNotFoundError as e: print(f"找不到输入邮箱账号的元素{e}") @@ -824,7 +889,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) print("输入邮箱账号运行完毕") save_log(random_number, "输入邮箱账号运行完毕") @@ -847,7 +912,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) retry_with_recovery(tab, hwnd, email_account) @@ -868,7 +933,13 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re # 输入密码 password_input = tab.ele('@@aria-label=输入您的密码@@type=password', timeout=15) if password_input: - input_password(tab, hwnd, email_password, password_input) # 使用传入的邮箱密码 + flag = input_password(tab, hwnd, email_password, password_input) # 使用传入的邮箱密码 + if flag: + update_status_in_db(email_account, "密码的下一步无法点击") + return ( + email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, + proxy_port, + proxy_username, proxy_password, region) random_sleep(tab) except ElementNotFoundError as e: print(f"找不到密码输入框的元素:{e}") @@ -877,7 +948,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) print("输入旧密码运行完毕") save_log(random_number, "输入旧密码运行完毕") @@ -901,7 +972,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_recovery_email, new_password, proxy_host, proxy_port, - proxy_username, proxy_password, row_index) + proxy_username, proxy_password) try: # 输入密码 @@ -916,7 +987,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) print("如果出现错误,输入密码运行完毕") save_log(random_number, "如果出现错误后,输入密码运行完毕") @@ -925,6 +996,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re # 看下是否出现了手机号 telephone = tab.ele("@text()=请输入电话号码,以便通过短信接收验证码。", timeout=5) if telephone: + save_log(random_number, '接码') update_status_in_db(email_account, '接码') browser.quit() return email_account @@ -956,7 +1028,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) print("输入新密码运行完毕") save_log(random_number, "输入新密码运行完毕") @@ -975,7 +1047,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) print("点击辅助邮箱验证运行完毕") save_log(random_number, "点击辅助邮箱验证运行完毕") @@ -995,8 +1067,12 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re print("我要开始修改辅助邮箱账号了") try: - modify_the_secondary_email1(tab, new_recovery_email) # 使用传入的新辅助邮箱 - print("修改完成") + button = tab.ele('@@tag()=i@@text()=edit', timeout=15) + if button: + modify_the_secondary_email1(tab, new_recovery_email) # 使用传入的新辅助邮箱 + print("修改完成") + else: + print("没有修改辅助邮箱的界面,跳过") # auxiliary_email_account_change = True except ElementNotFoundError as e: # 捕获并打印异常,不中断后续代码执行 @@ -1006,7 +1082,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, row_index) + proxy_username, proxy_password) else: print("辅助邮箱账号已经被更改过") save_log(random_number, "辅助邮箱账号已经被更改过") @@ -1017,9 +1093,8 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re save_log(random_number, "修改辅助邮箱1运行完毕") if password_change and auxiliary_email_account_change: - update_status_in_db(email_account, '已更改') logutGoogle(tab) - browser.quit() + update_status_in_db(email_account, '已更改') return email_account tab.handle_alert(accept=True) @@ -1036,7 +1111,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) try: # 点击头像进入邮箱的安全设置 @@ -1052,7 +1127,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) tab.wait(3) @@ -1072,19 +1147,20 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) tab.wait(1) try: if auxiliary_email_account_change: + logutGoogle(tab) update_status_in_db(email_account, '已更改') return email_account # 修改辅助邮箱2 flag = modify_the_secondary_email2(tab, new_recovery_email, new_password, hwnd) save_log(random_number, f"辅助邮箱是否被修改:{flag}") if flag: - browser.quit() + logutGoogle(tab) update_status_in_db(email_account, '已更改') return email_account else: @@ -1096,10 +1172,12 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re # 最多尝试3次循环 for attempt in range(3): print(f"第 {attempt + 1} 次尝试检查验证码...") + save_log(random_number, f"第 {attempt + 1} 次尝试检查验证码...") # 获取当前程序运行的时间 current_time = datetime.now(timezone.utc) print(f"当前时间为{current_time}") + save_log(random_number, f"当前时间为{current_time}") # 检查验证码,超时时间为300秒,使用当前时间作为 start_time try: @@ -1126,6 +1204,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re tab.wait(5) print("点击确定") + save_log(random_number, "点击确定") # 检查是否有报错提示 is_visible = tab.ele('@@id=c4@@tag()=p@@role=alert', timeout=1) @@ -1135,11 +1214,15 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re sent_code_button = tab.ele('@text():Send a new code.', timeout=15) if sent_code_button: print(f"重新发送邮件的按钮为:{sent_code_button}") + save_log(random_number, f"重新发送邮件的按钮为:{sent_code_button}") sent_code_button.click(by_js=True) continue else: # 如果没有报错,退出 print("辅助邮箱账号已经更改完毕") + save_log(random_number, "辅助邮箱账号已经更改完毕") + logutGoogle(tab) + update_status_in_db(email_account, "已更改") break else: # 如果未找到验证码,点击重新发送按钮并进入下一次循环 @@ -1150,6 +1233,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re continue except TimeoutError: print("超时未收到验证码,重新发送") + save_log(random_number, "超时未收到验证码,重新发送") sent_code_button = tab.ele('@text():Send a new code.', timeout=15) if sent_code_button: sent_code_button.click(by_js=True) @@ -1160,7 +1244,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) except Exception as e: print(f"出现未知错误:{e}") save_log(random_number, f"出现未知错误:{e}") @@ -1168,23 +1252,25 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re return ( email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, proxy_port, - proxy_username, proxy_password, region, row_index) + proxy_username, proxy_password, region) finally: - # browser.quit() - # 释放资源 - time.sleep(5) - delete_folder(plugin_path) - delete_folder(user_dir) - - - + try: + browser.quit() + # 释放资源 + time.sleep(5) + delete_folder(plugin_path) + delete_folder(user_dir) + except Exception: + print("出现没有代理") + save_log(random_number, "出现没有代理") def run_gui(): stop_flag = threading.Event() # 用于控制任务中止的标志位 exec_thread = None # 用于存储后台线程的引用 + def handle_file_select(): file_path = filedialog.askopenfilename( title="选择 Excel 文件", @@ -1196,18 +1282,56 @@ def run_gui(): def update_proxy_stats(): try: - # 从 ProxyManager 获取代理总数 - total_proxies = proxy_manager.get_proxy_count("ALL") - print(f"更新代理信息的总数:{total_proxies}") + # 国家代码列表 + countries = { + "AT": "奥地利", "BE": "比利时", "CZ": "捷克", "DE": "德国", "DK": "丹麦", + "ES": "西班牙", "FI": "芬兰", "FR": "法国", "GB": "英国", "HR": "克罗地亚", + "HU": "匈牙利", "IT": "意大利", "LT": "立陶宛", "LU": "卢森堡", "NL": "荷兰", + "PL": "波兰", "PT": "葡萄牙", "RO": "罗马尼亚", "SE": "瑞典", "SK": "斯洛伐克" + } - # 更新标签内容 - proxy_stats = f"总数: {total_proxies}" # 只显示总代表数量 + # 获取全部区域的代理数量 + try: + total_proxies = proxy_manager.get_proxy_count("ALL") + except Exception as e: + total_proxies = "获取失败" + print(f"获取全部代理数时出错: {e}") + + # 显示总代表数量 + proxy_stats = f"总数: {total_proxies} 个代理\n\n" + + # 获取并显示每个国家的代理数量 + country_data = [] + for country_code, country_name in countries.items(): + try: + # 获取该国家的代理数量 + country_proxy_count = proxy_manager.get_proxy_count(country_code) + country_data.append(f"{country_name}({country_code}): {country_proxy_count} 个代理") + except Exception as e: + country_data.append(f"{country_name}({country_code}): 获取代理数失败") + print(f"获取 {country_name} ({country_code}) 代理数时出错: {e}") + + # 更新界面上的代理统计标签 lbl_proxy_stats.config(text=proxy_stats) + # 分列显示国家的代理统计信息 + max_rows = 5 # 每列最多显示多少行 + columns = 4 # 显示几列 + for col in range(columns): + for row in range(min(max_rows, len(country_data) - col * max_rows)): + label = tk.Label(root, text=country_data[col * max_rows + row], justify="left") + label.grid(row=row + 9, column=col, padx=5, pady=5, sticky="w") + + # 为每列添加居中对齐,使用 columnspan 来确保列宽 + for col in range(columns): + root.grid_columnconfigure(col, weight=1, uniform="equal") + + # 调整列之间的间距,通过 columnconfigure 设置每列最小宽度(minsize) + for col in range(columns): + root.grid_columnconfigure(col, minsize=5) except Exception as e: print(f"更新代理统计信息时出错: {e}") lbl_proxy_stats.config(text="获取代理统计信息失败") - def start_processing(): file_path = entry_file_path.get() sheet_name = entry_sheet_name.get() @@ -1259,14 +1383,15 @@ def run_gui(): # 验证重试次数 try: max_retries = int(max_retries) - if max_retries < 0: - raise ValueError("重试次数必须是大于或等于0的整数!") + if max_retries < 0 or max_retries > 3: + raise ValueError("重试次数必须是整数且在0到3之间!") except ValueError as e: messagebox.showerror("错误", f"无效的重试次数:{e}") return + db_manager.import_from_excel(file_path, clear_old=True) # 初始化 Excel 数据和进度条状态 - all_rows = read_data_from_db(file_path) # 读取 Excel 数据 + all_rows = read_data_from_db() # 读取 Excel 数据 total_tasks = len(all_rows) completed_count = 0 failed_count = 0 @@ -1297,29 +1422,25 @@ def run_gui(): def parallel_execution_with_db(file_path, max_concurrency, max_retries): progress_queue = Queue() - all_rows = read_data_from_db(file_path) # 从数据库中读取数据 + all_rows = read_data_from_db() # 第一次读取数据 print(f"数据库中的数据:{all_rows}") - failed_rows = [] + total_rows = len(all_rows) completed_count = 0 failed_count = 0 - failed_emails = set() # 用于存储唯一的失败邮箱 - # 更新进度条的总条目数 progress_bar['maximum'] = total_rows + retry_count = 0 - - with Pool(processes=max_concurrency) as pool: - retry_count = 0 - while all_rows or failed_rows: + with Pool(processes=max_concurrency, initializer=init_worker()) as pool: + while all_rows: if stop_flag.is_set(): print("停止信号已接收,中止任务!") break - rows_to_process = all_rows + failed_rows # 处理所有待处理和失败的行 results = [] - for i, row in enumerate(rows_to_process): + for i, row in enumerate(all_rows): if stop_flag.is_set(): print("停止信号已接收,中止任务!") break @@ -1335,20 +1456,16 @@ def run_gui(): proxy = proxy_manager.get_random_proxy_by_region(region=region, remove_after_fetch=True) if proxy: # 如果分配成功 - proxy_host, proxy_port, proxy_user, proxy_pass = proxy['host'], proxy['port'], proxy[ - 'user'], proxy['password'] - print( - f"为账号 {account_email} 分配代理:{proxy_host}:{proxy_port}:{proxy_user}:{proxy_pass}") + proxy_host, proxy_port, proxy_user, proxy_pass = proxy['host'], proxy['port'], proxy['user'], \ + proxy['password'] + print(f"为账号 {account_email} 分配代理:{proxy_host}:{proxy_port}:{proxy_user}:{proxy_pass}") - # 将分配的代理信息传递到数据库中输入邮箱账号运行完毕 db_manager.update_record(account_email, proxy=f"{proxy_host}:{proxy_port}:{proxy_user}:{proxy_pass}") row = row[:5] + (proxy_host, proxy_port, proxy_user, proxy_pass) + row[9:] # 将代理信息加入到数据行中 else: print(f"为账号 {account_email} 分配代理失败,跳过此账号。") - - # 使用写入锁保护 export_proxies with write_lock: try: print("更新剩余可用IP") @@ -1359,65 +1476,50 @@ def run_gui(): update_proxy_stats() # 传递锁给子进程,并将当前账号数据传递给 main 函数 - result = pool.apply_async( - main, args=(row), - callback=lambda result: progress_queue.put(result) - ) + result = pool.apply_async(main, args=(row), callback=lambda result: progress_queue.put(result)) results.append(result) - all_rows = [] - failed_rows = [] + for result in results: - try: retry_row = result.get() print(f"main函数返回的值: {retry_row}") - if isinstance(retry_row, tuple): # 返回的是元组,表示需要重试 - email = retry_row[0] # 假设元组的第一个元素是邮箱地址 - if email not in failed_emails: # 检查是否是新的失败邮箱 - failed_emails.add(email) # 添加到失败集合 - failed_count += 1 # 增加失败计数 - failed_rows.append(retry_row) # 添加到重试列表 - - lbl_progress_status.config( - text=f"完成:{completed_count}/{total_rows},失败:{failed_count}" - ) - + if not retry_row: # 如果返回False,表示任务失败 + failed_count += 1 + elif isinstance(retry_row, tuple): # 返回的是元组,表示需要重试 + failed_count += 1 # 增加失败计数 else: # 返回的是单个 account,表示成功 completed_count += 1 - progress_bar['value'] = completed_count # 更新进度条值(百分比) - lbl_progress_status.config( - text=f"完成:{completed_count}/{total_rows},失败:{failed_count}" - ) - - + # 更新进度条和显示的状态 + progress_bar['value'] = completed_count + lbl_progress_status.config(text=f"完成:{completed_count}/{total_rows},失败:{failed_count}") time.sleep(2) # 模拟耗时操作 except Exception as e: print(f"任务执行时发生错误: {e}") failed_count += 1 - lbl_progress_status.config( - text=f"完成:{completed_count}/{total_rows},失败:{failed_count}" - ) + lbl_progress_status.config(text=f"完成:{completed_count}/{total_rows},失败:{failed_count}") messagebox.showwarning("任务执行错误", f"任务执行时发生错误: {e}") + # 如果停止信号被触发,则中止 if stop_flag.is_set(): print("停止信号已接收,中止任务!") break - if len(failed_rows) > 0 and retry_count < max_retries: + # 重试逻辑,重新从数据库读取失败的数据 + if retry_count < max_retries: retry_count += 1 - all_rows = failed_rows - failed_rows = [] - elif retry_count >= max_retries: + all_rows = read_data_from_db() # 重新从数据库读取失败的记录 + else: print("达到最大重试次数,停止重试。") break - else: - print("所有任务已完成。") - messagebox.showinfo('运行结束', '所有任务已经完成') - def read_data_from_db(file_path: str) -> List[Tuple]: + else: + print("所有任务已完成。") + messagebox.showinfo('运行结束', '所有任务已经完成') + + def read_data_from_db() -> List[Tuple]: """ 从数据库读取数据,同时保持与旧的接口和逻辑一致。 根据账号区域自动分配代理,并导入到数据库。 @@ -1427,9 +1529,6 @@ def run_gui(): skip_keywords = {"已更改", "接码", "被盗"} data = [] - # 导入 Excel 数据到数据库,清空旧数据 - db_manager.import_from_excel(file_path, clear_old=True) - # 从数据库中查询所有数据 accounts = db_manager.export_data() @@ -1447,7 +1546,7 @@ def run_gui(): # 不再分配代理,只是记录账号信息 data.append(( account.email, account.original_password, account.original_aux_email, - account.new_password, account.new_aux_email, "", "", "", "",account.region, i + 2 + account.new_password, account.new_aux_email, "", "", "", "",account.region )) return data @@ -1493,7 +1592,7 @@ def run_gui(): # 添加显示代理统计信息的标签 tk.Label(root, text="代理统计信息:").grid(row=8, column=0, padx=10, pady=10) lbl_proxy_stats = tk.Label(root, text="代理统计信息未加载") - lbl_proxy_stats.grid(row=8, column=1, padx=10, pady=10, columnspan=2) + lbl_proxy_stats.grid(row=8, column=1, padx=5, pady=10, columnspan=2) root.protocol("WM_DELETE_WINDOW", on_closing) # 绑定窗口关闭事件 root.mainloop()