File size: 3,293 Bytes
8ab43a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys
import json
import logging
from datetime import datetime

# Setup absolute paths for the API directory
API_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "book-of-souls-json-api"))
sys.path.append(API_DIR)

# Configure logging to suppress verbose API logs if needed
api_logger = logging.getLogger("book_of_souls_api")
api_logger.setLevel(logging.WARNING)

# Global imports from the API
try:
    original_cwd = os.getcwd()
    os.chdir(API_DIR)
    
    from gematria import calculate_gematria
    from utils import translate_date_to_words
    import torah
    import bible
    from deep_translator import GoogleTranslator
    
    os.chdir(original_cwd)
except Exception as e:
    print(f"Error importing modules: {e}")
    calculate_gematria = None
    translate_date_to_words = None

def get_oracle_data(name_or_topic: str):
    """
    Queries the Book of Souls logic for a specific name/topic.
    """
    if not calculate_gematria:
        return {"error": "Oracle modules not properly initialized."}

    original_cwd = os.getcwd()
    os.chdir(API_DIR)
    
    try:
        date_obj = datetime.now()
        date_words = translate_date_to_words(date_obj)
        
        # Calculate Gematria Sum (Step)
        gematria_sum = calculate_gematria(name_or_topic)
        
        if gematria_sum < 2:
            gematria_sum = 42
        
        step = gematria_sum
        rounds = "1,-1"
        length = 200
        tlang = "de"
        strip_spaces = True
        strip_in_braces = True
        strip_diacritics_chk = True
        translate = True # Enable automated translation

        results = []
        
        # Torah: start 1, end 5
        res_torah = torah.process_json_files(1, 5, step, rounds, length, tlang, strip_spaces, strip_in_braces, strip_diacritics_chk, translate)
        if res_torah: results.extend(res_torah)
        
        # Bible: start 40, end 45
        res_bible = bible.process_json_files(40, 45, step, rounds, length, tlang, strip_spaces, strip_in_braces, strip_diacritics_chk, translate)
        if res_bible: results.extend(res_bible)

        return {
            "search_phrase": f"{date_words} {name_or_topic}",
            "gematria_step": step,
            "results": results[:5]
        }
    finally:
        os.chdir(original_cwd)

def format_oracle_response(data: dict, topic: str) -> str:
    """Formats the JSON result into a prophetic response."""
    if not data or "error" in data:
        return f"Das Orakel ist getrübt: {data.get('error', 'Keine Verbindung zum Buch der Seelen.')}"
    
    results = data.get("results", [])
    if not results:
        return f"Das Schicksalsbuch schweigt zum Thema '{topic}'. Die Sterne verweigern im Moment die Antwort."

    header = f"🔮 **Prophezeiung des Orakels für: {topic}**\n\n"
    header += f"*Der Gematria-Schlüssel liegt bei {data['gematria_step']}.*\n\n"
    
    content = ""
    for i, res in enumerate(results, 1):
        text = res.get("translated_text") or res.get("result_text") or "..."
        book = res.get("book", "Unbekannte Quelle")
        content += f"**Vision {i} ({book}):**\n> \"{text}\"\n\n"
    
    footer = "Deute diese Zeichen weise. Das Buch der Seelen hat gesprochen."
    return header + content + footer