remove test scripts and update gitignore
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -85,3 +85,7 @@ Thumbs.db
|
||||
# ProxyPool Specific
|
||||
db/
|
||||
proxies.sqlite*
|
||||
|
||||
# Test/Maintenance Scripts
|
||||
clear_*.py
|
||||
test_*.py
|
||||
|
||||
@@ -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)
|
||||
@@ -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())
|
||||
Reference in New Issue
Block a user