fix quality code

This commit is contained in:
2026-02-01 23:03:23 +03:00
parent 731e68a597
commit f8962225ee
106 changed files with 8456 additions and 5810 deletions

View File

@@ -2,6 +2,7 @@
"""
Скрипт для диагностики и очистки проблем с голосовыми файлами
"""
import asyncio
import os
import sys
@@ -24,15 +25,15 @@ async def main():
if not os.path.exists(db_path):
logger.error(f"База данных не найдена: {db_path}")
return
bot_db = AsyncBotDB(db_path)
cleanup_utils = VoiceFileCleanupUtils(bot_db)
print("=== Диагностика голосовых файлов ===")
# Запускаем полную диагностику
diagnostic_result = await cleanup_utils.run_full_diagnostic()
print(f"\n📊 Статистика диска:")
if "error" in diagnostic_result["disk_stats"]:
print(f" ❌ Ошибка: {diagnostic_result['disk_stats']['error']}")
@@ -41,59 +42,65 @@ async def main():
print(f" 📁 Директория: {stats['directory']}")
print(f" 📄 Всего файлов: {stats['total_files']}")
print(f" 💾 Размер: {stats['total_size_mb']} MB")
print(f"\n🗄️ База данных:")
print(f" 📝 Записей в БД: {diagnostic_result['db_records_count']}")
print(f" 🔍 Записей без файлов: {diagnostic_result['orphaned_db_records_count']}")
print(
f" 🔍 Записей без файлов: {diagnostic_result['orphaned_db_records_count']}"
)
print(f" 📁 Файлов без записей: {diagnostic_result['orphaned_files_count']}")
print(f"\n📋 Статус: {diagnostic_result['status']}")
if diagnostic_result['status'] == 'issues_found':
if diagnostic_result["status"] == "issues_found":
print("\n⚠️ Найдены проблемы!")
if diagnostic_result['orphaned_db_records_count'] > 0:
if diagnostic_result["orphaned_db_records_count"] > 0:
print(f"\n🗑️ Записи в БД без файлов (первые 10):")
for file_name, user_id in diagnostic_result['orphaned_db_records']:
for file_name, user_id in diagnostic_result["orphaned_db_records"]:
print(f" - {file_name} (user_id: {user_id})")
if diagnostic_result['orphaned_files_count'] > 0:
if diagnostic_result["orphaned_files_count"] > 0:
print(f"\n📁 Файлы без записей в БД (первые 10):")
for file_path in diagnostic_result['orphaned_files']:
for file_path in diagnostic_result["orphaned_files"]:
print(f" - {file_path}")
# Предлагаем очистку
print("\n🧹 Хотите выполнить очистку?")
print("1. Удалить записи в БД без файлов")
print("2. Удалить файлы без записей в БД")
print("3. Выполнить полную очистку")
print("4. Выход")
choice = input("\nВыберите действие (1-4): ").strip()
if choice == "1":
print("\n🗑️ Удаление записей в БД без файлов...")
deleted = await cleanup_utils.cleanup_orphaned_db_records(dry_run=False)
print(f"✅ Удалено {deleted} записей")
elif choice == "2":
print("\n📁 Удаление файлов без записей в БД...")
deleted = await cleanup_utils.cleanup_orphaned_files(dry_run=False)
print(f"✅ Удалено {deleted} файлов")
elif choice == "3":
print("\n🧹 Полная очистка...")
db_deleted = await cleanup_utils.cleanup_orphaned_db_records(dry_run=False)
files_deleted = await cleanup_utils.cleanup_orphaned_files(dry_run=False)
db_deleted = await cleanup_utils.cleanup_orphaned_db_records(
dry_run=False
)
files_deleted = await cleanup_utils.cleanup_orphaned_files(
dry_run=False
)
print(f"✅ Удалено {db_deleted} записей в БД и {files_deleted} файлов")
elif choice == "4":
print("👋 Выход...")
else:
print("❌ Неверный выбор")
else:
print("\n✅ Проблем не найдено!")
except Exception as e:
logger.error(f"Ошибка в скрипте: {e}")
print(f"❌ Ошибка: {e}")