first commit
This commit is contained in:
33
clear_database.py
Normal file
33
clear_database.py
Normal file
@@ -0,0 +1,33 @@
|
||||
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