File size: 2,711 Bytes
3045238
 
99b3ef5
3045238
 
a676448
 
3045238
e4ee4df
3045238
 
420ea26
 
 
 
 
3045238
 
 
1b969ef
a676448
420ea26
 
 
e4ee4df
420ea26
a676448
 
420ea26
a676448
e4ee4df
420ea26
 
e4ee4df
420ea26
 
 
 
3045238
420ea26
3045238
 
 
420ea26
e4ee4df
 
 
 
 
420ea26
e4ee4df
 
 
3045238
 
e4ee4df
1b969ef
 
e4ee4df
420ea26
 
3045238
e4ee4df
1b969ef
 
 
 
420ea26
3045238
 
420ea26
 
 
1b969ef
 
3045238
 
 
a676448
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
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

import gradio as gr
from gradio_calendar import Calendar
from utils import date_to_words  # Annahme: utils.py enthält die date_to_words Funktion
from gematria import calculate_gematria, strip_diacritics
from datetime import datetime, timedelta
import json

# --- Helper Functions ---
def calculate_gematria_sum(text):
    if text:
        text_gematria = calculate_gematria(strip_diacritics(text))
        return text_gematria
    else:
        return None

def perform_gematria_calculation_for_date_range(start_date, end_date):
    logger.info(f"Startdatum: {start_date}, Enddatum: {end_date}")  # Debugging-Ausgabe
    results = {}
    delta = timedelta(days=1)
    current_date = start_date

    while current_date <= end_date:
        date_words = date_to_words(current_date)
        logger.info(f"Datum: {current_date}, Tagesnamen: {date_words}")  # Debugging-Ausgabe
        gematria_sum = calculate_gematria_sum(date_words)
        logger.info(f"Gematria-Summe: {gematria_sum}")  # Debugging-Ausgabe

        if gematria_sum not in results:
            results[gematria_sum] = []

        results[gematria_sum].append({
            "date": current_date.strftime('%Y-%m-%d'),
            "date_words": date_words
        })

        current_date += delta

    return results

def generate_json_output(results, start_date, end_date):
    result = {
        "DateRange": {
            "StartDate": start_date.strftime("%Y-%m-%d"),
            "EndDate": end_date.strftime("%Y-%m-%d")
        },
        "Results": results
    }
    return json.dumps(result, indent=4, ensure_ascii=False)

# --- Main Gradio App ---
with gr.Blocks() as app:
    with gr.Row():
        start_date = Calendar(type="datetime", label="Start Date")  # Zurück zu "datetime"
        end_date = Calendar(type="datetime", label="End Date")    # Zurück zu "datetime"

    calculate_btn = gr.Button("Calculate Gematria for Date Range")
    json_output = gr.Textbox(label="JSON Output")

    # --- Event Handlers ---
    def perform_calculation(start_date, end_date):  # Empfange datetime-Objekte
        logger.info(f"perform_calculation aufgerufen mit: start_date={start_date}, end_date={end_date}")
        results = perform_gematria_calculation_for_date_range(start_date, end_date)
        json_result = generate_json_output(results, start_date, end_date)
        return json_result

    # --- Event Triggers ---
    calculate_btn.click(
        perform_calculation,
        inputs=[start_date, end_date],
        outputs=[json_output],
        api_name="calculate_gematria"
    )

if __name__ == "__main__":
    app.launch(share=False)