File size: 5,021 Bytes
d892643 |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
import subprocess
import sys
import os
# Funktion zum Installieren von Bibliotheken, falls sie fehlen
def install(package):
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
print(f"{package} erfolgreich installiert.")
except Exception as e:
print(f"Fehler bei der Installation von {package}: {e}")
# Liste der benötigten Bibliotheken
required_packages = ['requests', 'mammoth', 'pip']
# Installiere alle benötigten Bibliotheken
for package in required_packages:
try:
__import__(package)
except ImportError:
print(f"Bibliothek {package} nicht gefunden. Versuche, sie zu installieren...")
install(package)
# Funktion zum Lesen und Verarbeiten der Word-Datei
def read_instructions(word_file):
try:
import mammoth
with open(word_file, "rb") as docx_file:
result = mammoth.extract_raw_text(docx_file)
text = result.value # Der gesamte Text aus der Word-Datei
instructions = parse_instructions(text)
return instructions
except FileNotFoundError:
print(f"Die Datei {word_file} wurde nicht gefunden. Stelle sicher, dass sie im richtigen Verzeichnis ist.")
return None
except Exception as e:
print(f"Fehler beim Auslesen der Datei: {e}")
return None
# Funktion zur Analyse der Anweisungen aus dem Text
def parse_instructions(text):
try:
instructions = {}
current_section = None
lines = text.split("\n")
for line in lines:
if line.startswith("Finanzen"):
current_section = "Finanzen"
instructions[current_section] = []
elif line.startswith("Social Media"):
current_section = "Social Media"
instructions[current_section] = []
elif line.startswith("App-Integration"):
current_section = "App-Integration"
instructions[current_section] = []
elif line.startswith("Ernährung"):
current_section = "Ernährung und Wohlbefinden"
instructions[current_section] = []
elif current_section and line.strip():
instructions[current_section].append(line.strip())
return instructions
except Exception as e:
print(f"Fehler beim Verarbeiten der Anweisungen: {e}")
return {}
# Funktion zur Ausführung der Anweisungen
def execute_instructions(instructions):
try:
if 'Finanzen' in instructions:
print("Finanzanalyse durchführen...")
analyze_finances()
if 'Social Media' in instructions:
print("Social Media Beiträge planen...")
plan_social_media_posts()
if 'App-Integration' in instructions:
print("Apps analysieren und integrieren...")
analyze_and_integrate_apps()
if 'Ernährung und Wohlbefinden' in instructions:
print("Ernährungspläne erstellen...")
create_nutrition_plans()
except Exception as e:
print(f"Fehler bei der Ausführung der Anweisungen: {e}")
# Beispiel für weitere Funktionen mit Fehlerbehandlung
def analyze_finances():
try:
print("Starte die Finanzanalyse...")
# Hier fügst du den eigentlichen Code zur Finanzanalyse ein
except Exception as e:
print(f"Fehler bei der Finanzanalyse: {e}")
def plan_social_media_posts():
try:
print("Social Media Beiträge werden geplant...")
# Hier fügst du den Code zur Automatisierung der Social Media Postings ein
except Exception as e:
print(f"Fehler beim Planen der Social Media Beiträge: {e}")
def analyze_and_integrate_apps():
try:
print("Apps werden analysiert und in die Multifunktions-App integriert...")
# Hier fügst du den Code zur App-Analyse und Integration ein
except Exception as e:
print(f"Fehler beim Analysieren und Integrieren von Apps: {e}")
def create_nutrition_plans():
try:
print("Erstelle Ernährungspläne basierend auf deinem Budget...")
# Hier fügst du den Code zum Erstellen von Ernährungsplänen ein
except Exception as e:
print(f"Fehler beim Erstellen der Ernährungspläne: {e}")
# Hauptfunktion zum Auslesen und Verarbeiten der Datei
def run_ki_agent():
try:
# Speicherpfad für die Word-Datei (anpassbar für den PC)
save_path = os.path.join(os.getcwd(), 'KI_Agent_Steuerung.docx')
if os.path.exists(save_path):
print(f"Datei erfolgreich vorhanden im Verzeichnis: {save_path}")
instructions = read_instructions(save_path)
if instructions:
execute_instructions(instructions)
else:
print(f"Datei wurde nicht gefunden. Bitte stelle sicher, dass die Datei im Verzeichnis {save_path} liegt.")
except Exception as e:
print(f"Fehler im Hauptskript: {e}")
# Führe das Hauptskript aus
run_ki_agent() |