File: //opt/af/scripts/analyze_awp_posts.py
#!/usr/bin/env python3
"""
Temporäres Skript zur Analyse der awp_posts-Tabelle.
"""
import os
import sys
from dotenv import load_dotenv
# Füge das Hauptverzeichnis zum Python-Pfad hinzu
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
# Lade Umgebungsvariablen
load_dotenv()
from src.database.operations import execute_select_query, get_table_schema
def analyze_awp_posts():
"""Analysiert die Struktur der awp_posts-Tabelle und gibt einen Beispieldatensatz zurück."""
print("=== Analysiere awp_posts-Tabelle ===")
# Schema der Tabelle abrufen
schema = get_table_schema('awp_posts')
if not schema:
print("Fehler: Konnte das Schema der awp_posts-Tabelle nicht abrufen.")
return
print("Schema der awp_posts-Tabelle:")
for col, typ in schema.items():
print(f" - {col}: {typ}")
# Beispieldaten abrufen
query = """
SELECT *
FROM awp_posts
WHERE post_status = 'publish'
ORDER BY post_date DESC
LIMIT 1
"""
result = execute_select_query(query, return_type='dict')
if not result or len(result) == 0:
print("Keine Daten in der awp_posts-Tabelle gefunden.")
return
print("\nBeispieldatensatz:")
post = result[0]
for key, value in post.items():
# Limitiere die Ausgabe für längere Felder
if isinstance(value, str) and len(value) > 100:
value = value[:100] + "..."
print(f" - {key}: {value}")
# Spezifisch nach post_type-Werten suchen
query_types = """
SELECT DISTINCT post_type, COUNT(*) as count
FROM awp_posts
WHERE post_status = 'publish'
GROUP BY post_type
ORDER BY count DESC
"""
type_results = execute_select_query(query_types, return_type='dict')
if type_results and len(type_results) > 0:
print("\nVerfügbare post_types und Anzahl:")
for item in type_results:
print(f" - {item['post_type']}: {item['count']}")
if __name__ == "__main__":
analyze_awp_posts()