ich geh behindert
This commit is contained in:
148
backend/scripts/quick_unicode_fix.py
Normal file
148
backend/scripts/quick_unicode_fix.py
Normal file
@@ -0,0 +1,148 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Quick Unicode Fix für MYP Backend
|
||||
=================================
|
||||
|
||||
Behebt Unicode-Encoding-Probleme in logging_config.py
|
||||
für Windows CP1252-Umgebungen.
|
||||
|
||||
Verwendung: python quick_unicode_fix.py
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
def fix_unicode_in_file(file_path: Path):
|
||||
"""Ersetzt Unicode-Emojis durch ASCII-Text in einer Datei"""
|
||||
|
||||
print(f"🔧 Bearbeite: {file_path}")
|
||||
|
||||
# Emoji-Ersetzungen definieren
|
||||
replacements = {
|
||||
'\\u2705': '[OK]', # ✅ -> [OK]
|
||||
'\\u274c': '[ERROR]', # ❌ -> [ERROR]
|
||||
'\\u26a0': '[WARN]', # ⚠️ -> [WARN]
|
||||
'\\u2139': '[INFO]', # ℹ️ -> [INFO]
|
||||
'✅': '[OK]',
|
||||
'❌': '[ERROR]',
|
||||
'⚠️': '[WARN]',
|
||||
'ℹ️': '[INFO]',
|
||||
# Weitere häufige Emojis
|
||||
'🚀': '[START]',
|
||||
'🔄': '[RESTART]',
|
||||
'📋': '[LIST]',
|
||||
'🎉': '[SUCCESS]',
|
||||
'💥': '[CRASH]',
|
||||
'🔍': '[SEARCH]',
|
||||
'📊': '[STATS]',
|
||||
'🛑': '[STOP]',
|
||||
'⏭️': '[SKIP]',
|
||||
'🚨': '[ALERT]',
|
||||
}
|
||||
|
||||
try:
|
||||
# Datei lesen
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
original_content = content
|
||||
changes_made = 0
|
||||
|
||||
# Ersetzungen durchführen
|
||||
for emoji, replacement in replacements.items():
|
||||
if emoji in content:
|
||||
content = content.replace(emoji, replacement)
|
||||
changes_made += 1
|
||||
print(f" ✓ Ersetzt: {emoji} -> {replacement}")
|
||||
|
||||
# UTF-8 Encoding-Zwang hinzufügen (falls nicht vorhanden)
|
||||
encoding_fix = """
|
||||
# UTF-8 Encoding für Windows-Kompatibilität
|
||||
import sys
|
||||
if hasattr(sys.stdout, 'reconfigure'):
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
except:
|
||||
pass
|
||||
"""
|
||||
|
||||
if "sys.stdout.reconfigure" not in content:
|
||||
# Füge nach den Imports ein
|
||||
import_pattern = r'(import\s+.*?\n)(\n*)(class|def|\w+\s*=)'
|
||||
if re.search(import_pattern, content, re.MULTILINE):
|
||||
content = re.sub(
|
||||
import_pattern,
|
||||
r'\1' + encoding_fix + r'\n\3',
|
||||
content,
|
||||
count=1,
|
||||
flags=re.MULTILINE
|
||||
)
|
||||
changes_made += 1
|
||||
print(f" ✓ UTF-8 Encoding-Fix hinzugefügt")
|
||||
|
||||
# Datei schreiben (nur wenn Änderungen)
|
||||
if changes_made > 0:
|
||||
# Backup erstellen
|
||||
backup_path = file_path.with_suffix(f'{file_path.suffix}.backup')
|
||||
with open(backup_path, 'w', encoding='utf-8') as f:
|
||||
f.write(original_content)
|
||||
print(f" 📂 Backup erstellt: {backup_path}")
|
||||
|
||||
# Geänderte Datei schreiben
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
|
||||
print(f" ✅ {changes_made} Änderungen gespeichert")
|
||||
else:
|
||||
print(f" ℹ️ Keine Änderungen erforderlich")
|
||||
|
||||
return changes_made
|
||||
|
||||
except Exception as e:
|
||||
print(f" ❌ Fehler bei {file_path}: {e}")
|
||||
return 0
|
||||
|
||||
def main():
|
||||
"""Hauptfunktion - führt Unicode-Fix durch"""
|
||||
|
||||
print("🚀 MYP Backend Unicode-Fix")
|
||||
print("=" * 50)
|
||||
|
||||
backend_dir = Path(__file__).parent
|
||||
files_to_fix = [
|
||||
backend_dir / "utils" / "logging_config.py",
|
||||
backend_dir / "app_cleaned.py",
|
||||
backend_dir / "app.py",
|
||||
]
|
||||
|
||||
total_changes = 0
|
||||
fixed_files = 0
|
||||
|
||||
for file_path in files_to_fix:
|
||||
if file_path.exists():
|
||||
changes = fix_unicode_in_file(file_path)
|
||||
total_changes += changes
|
||||
if changes > 0:
|
||||
fixed_files += 1
|
||||
else:
|
||||
print(f"⚠️ Datei nicht gefunden: {file_path}")
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("📊 ZUSAMMENFASSUNG")
|
||||
print("=" * 50)
|
||||
print(f"✅ Bearbeitete Dateien: {len([f for f in files_to_fix if f.exists()])}")
|
||||
print(f"🔧 Dateien mit Änderungen: {fixed_files}")
|
||||
print(f"📝 Gesamte Änderungen: {total_changes}")
|
||||
|
||||
if total_changes > 0:
|
||||
print(f"\n🎉 Unicode-Fix erfolgreich angewendet!")
|
||||
print(f"💡 Teste jetzt: python -c \"import app_cleaned\"")
|
||||
else:
|
||||
print(f"\nℹ️ Keine Unicode-Probleme gefunden.")
|
||||
|
||||
print("\n🔄 Für Systemweite UTF-8-Unterstützung:")
|
||||
print(" set PYTHONIOENCODING=utf-8")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user