From 253350d1f286be352748d5a612aa4704f60d9397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=80=E6=A2=A6?= <3501646051@qq.com> Date: Tue, 27 Jan 2026 21:29:57 +0800 Subject: [PATCH] remove test scripts and update gitignore --- .gitignore | 4 ++++ clean_protocol_data.py | 49 ------------------------------------------ clear_database.py | 33 ---------------------------- 3 files changed, 4 insertions(+), 82 deletions(-) delete mode 100644 clean_protocol_data.py delete mode 100644 clear_database.py diff --git a/.gitignore b/.gitignore index 7e49221..394cd67 100644 --- a/.gitignore +++ b/.gitignore @@ -85,3 +85,7 @@ Thumbs.db # ProxyPool Specific db/ proxies.sqlite* + +# Test/Maintenance Scripts +clear_*.py +test_*.py diff --git a/clean_protocol_data.py b/clean_protocol_data.py deleted file mode 100644 index d47fcfc..0000000 --- a/clean_protocol_data.py +++ /dev/null @@ -1,49 +0,0 @@ -import asyncio -import aiosqlite -import os - -async def clean_protocol_data(): - """清理数据库中协议字段异常的数据""" - - db_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'db') - db_path = os.path.join(db_dir, 'proxies.sqlite') - - VALID_PROTOCOLS = ['http', 'https', 'socks4', 'socks5'] - - async with aiosqlite.connect(db_path) as db: - # 查询异常的协议数据 - async with db.execute('SELECT ip, port, protocol FROM proxies WHERE protocol NOT IN (?, ?, ?, ?)', VALID_PROTOCOLS) as cursor: - invalid_proxies = await cursor.fetchall() - - if invalid_proxies: - print(f"发现 {len(invalid_proxies)} 条异常协议数据:") - for ip, port, protocol in invalid_proxies: - print(f" - {ip}:{port} (protocol={protocol})") - - # 更新所有不是有效协议类型的记录为 'http' - cursor = await db.execute(''' - UPDATE proxies - SET protocol = 'http' - WHERE protocol NOT IN (?, ?, ?, ?) - ''', VALID_PROTOCOLS) - - updated_count = cursor.rowcount - await db.commit() - - print(f"\n已将 {updated_count} 条记录的协议更新为 'http'") - - # 统计修复后的协议分布 - print("\n修复后的协议分布:") - for protocol in VALID_PROTOCOLS: - async with db.execute('SELECT COUNT(*) FROM proxies WHERE protocol = ?', (protocol,)) as cursor: - count = (await cursor.fetchone())[0] - print(f" - {protocol}: {count} 条") - -if __name__ == "__main__": - print("=" * 60) - print("开始清理数据库中的异常协议数据...") - print("=" * 60) - asyncio.run(clean_protocol_data()) - print("=" * 60) - print("清理完成!") - print("=" * 60) diff --git a/clear_database.py b/clear_database.py deleted file mode 100644 index 028e0be..0000000 --- a/clear_database.py +++ /dev/null @@ -1,33 +0,0 @@ -import asyncio -import sys -import os -import aiosqlite - -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) - -from core.sqlite import SQLiteManager -from core.log import logger - -async def clear_proxies(): - db = SQLiteManager() - - try: - count_before = await db.count_proxies() - logger.info(f"清空前共有 {count_before} 个代理") - - async with aiosqlite.connect(db.db_path) as conn: - await conn.execute('DELETE FROM proxies') - await conn.commit() - - count_after = await db.count_proxies() - logger.info(f"清空后共有 {count_after} 个代理") - - print(f"✨ 成功清空数据库!删除了 {count_before} 个代理~") - return True - except Exception as e: - logger.error(f"清空数据库失败: {e}") - print(f"❌ 清空数据库失败: {e}") - return False - -if __name__ == "__main__": - asyncio.run(clear_proxies())