Files
AccountForger-neuerUpload/scripts/fix_x_accounts.py
Claude Project Manager f0320a9298 X-Problem gelöst
2025-09-14 02:47:52 +02:00

85 Zeilen
2.3 KiB
Python

#!/usr/bin/env python3
"""
Script to fix existing X accounts in the database.
Updates platform names from various formats to canonical 'x'.
"""
import sqlite3
import os
import sys
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from domain.value_objects.platform_name import PlatformName
def fix_x_accounts(db_path: str):
"""
Fix X accounts in the database by standardizing platform names.
Args:
db_path: Path to the database file
"""
if not os.path.exists(db_path):
print(f"❌ Database not found: {db_path}")
return
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Find all potential X accounts with different naming
possible_x_names = ['X', 'x', 'twitter', 'Twitter', 'X (Twitter)']
total_fixed = 0
for name in possible_x_names:
cursor.execute("SELECT COUNT(*) FROM accounts WHERE platform = ?", (name,))
count = cursor.fetchone()[0]
if count > 0:
print(f"Found {count} accounts with platform='{name}'")
# Update to canonical name
cursor.execute("UPDATE accounts SET platform = ? WHERE platform = ?", ('x', name))
total_fixed += count
print(f"✅ Updated {count} accounts from '{name}' to 'x'")
# Check for accounts that might have been missed
cursor.execute("SELECT DISTINCT platform FROM accounts")
all_platforms = cursor.fetchall()
print("\n📊 Current platforms in database:")
for platform in all_platforms:
cursor.execute("SELECT COUNT(*) FROM accounts WHERE platform = ?", (platform[0],))
count = cursor.fetchone()[0]
print(f" - {platform[0]}: {count} accounts")
# Commit changes
if total_fixed > 0:
conn.commit()
print(f"\n✅ Successfully fixed {total_fixed} accounts")
else:
print("\n✨ No accounts needed fixing")
conn.close()
def main():
"""Main function."""
# Database path
db_path = Path(__file__).parent.parent / "database" / "accounts.db"
print("🔧 X Platform Name Fix Script")
print("=" * 40)
print(f"Database: {db_path}")
print()
fix_x_accounts(str(db_path))
print("\n🎉 Done!")
if __name__ == "__main__":
main()