-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathdelete_disabled_zero_success_accounts.py
More file actions
51 lines (37 loc) · 1.29 KB
/
delete_disabled_zero_success_accounts.py
File metadata and controls
51 lines (37 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import sys
import asyncio
from pathlib import Path
from dotenv import load_dotenv
# Load .env file from parent directory
BASE_DIR = Path(__file__).resolve().parent.parent
load_dotenv(BASE_DIR / ".env")
# Add parent directory to path for imports
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from db import init_db, close_db
async def delete_disabled_accounts() -> int:
"""
Delete accounts where enabled=0 AND success_count=0 from the database.
Returns the number of rows deleted.
"""
db = await init_db()
try:
# Count first for clear reporting
count_row = await db.fetchone("SELECT COUNT(*) as cnt FROM accounts WHERE enabled=0 AND success_count=0")
count = count_row['cnt'] if count_row else 0
if count > 0:
await db.execute("DELETE FROM accounts WHERE enabled=0 AND success_count=0")
print(f"Deleted {count} disabled account(s) with zero success count.")
return int(count)
except Exception as e:
print(f"Database error: {e}", file=sys.stderr)
return 0
finally:
await close_db()
async def main_async() -> None:
await delete_disabled_accounts()
sys.exit(0)
def main() -> None:
asyncio.run(main_async())
if __name__ == "__main__":
main()