Spaces:
Sleeping
Sleeping
Commit
·
8992d21
1
Parent(s):
7a778e3
initial commit
Browse files
app.py
CHANGED
@@ -8,8 +8,17 @@ from gematria import calculate_gematria, strip_diacritics
|
|
8 |
from datetime import datetime, timedelta
|
9 |
import json
|
10 |
|
11 |
-
# ---
|
12 |
def calculate_gematria_sum(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
if text:
|
14 |
text_gematria = calculate_gematria(strip_diacritics(text))
|
15 |
return text_gematria
|
@@ -18,19 +27,29 @@ def calculate_gematria_sum(text):
|
|
18 |
|
19 |
def date_to_words(date_string):
|
20 |
"""
|
21 |
-
Konvertiert ein Datum im Format YYYY-MM-DD in die englische Schreibweise.
|
22 |
|
23 |
Args:
|
24 |
date_string: Ein Datum im Format YYYY-MM-DD.
|
25 |
|
26 |
Returns:
|
27 |
-
Einen String mit der englischen Schreibweise des
|
28 |
"""
|
29 |
date_obj = datetime.strptime(date_string, "%Y-%m-%d")
|
30 |
return date_obj.strftime("%A")
|
31 |
|
32 |
def perform_gematria_calculation_for_date_range(start_date, end_date):
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
results = {}
|
35 |
delta = timedelta(days=1)
|
36 |
current_date = start_date
|
@@ -39,9 +58,9 @@ def perform_gematria_calculation_for_date_range(start_date, end_date):
|
|
39 |
# Datum in String umwandeln
|
40 |
date_string = current_date.strftime("%Y-%m-%d")
|
41 |
date_words = date_to_words(date_string)
|
42 |
-
logger.info(f"Datum: {current_date},
|
43 |
gematria_sum = calculate_gematria_sum(date_words)
|
44 |
-
logger.info(f"Gematria-Summe: {gematria_sum}")
|
45 |
|
46 |
if gematria_sum not in results:
|
47 |
results[gematria_sum] = []
|
@@ -56,6 +75,17 @@ def perform_gematria_calculation_for_date_range(start_date, end_date):
|
|
56 |
return results
|
57 |
|
58 |
def generate_json_output(results, start_date, end_date):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
result = {
|
60 |
"DateRange": {
|
61 |
"StartDate": start_date.strftime("%Y-%m-%d"),
|
@@ -65,23 +95,33 @@ def generate_json_output(results, start_date, end_date):
|
|
65 |
}
|
66 |
return json.dumps(result, indent=4, ensure_ascii=False)
|
67 |
|
68 |
-
# ---
|
69 |
with gr.Blocks() as app:
|
70 |
with gr.Row():
|
71 |
-
start_date = Calendar(type="datetime", label="
|
72 |
-
end_date = Calendar(type="datetime", label="
|
73 |
|
74 |
-
calculate_btn = gr.Button("
|
75 |
-
json_output = gr.Textbox(label="JSON
|
76 |
|
77 |
-
# --- Event
|
78 |
def perform_calculation(start_date, end_date):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
logger.info(f"perform_calculation aufgerufen mit: start_date={start_date}, end_date={end_date}")
|
80 |
results = perform_gematria_calculation_for_date_range(start_date, end_date)
|
81 |
json_result = generate_json_output(results, start_date, end_date)
|
82 |
return json_result
|
83 |
|
84 |
-
# --- Event
|
85 |
calculate_btn.click(
|
86 |
perform_calculation,
|
87 |
inputs=[start_date, end_date],
|
|
|
8 |
from datetime import datetime, timedelta
|
9 |
import json
|
10 |
|
11 |
+
# --- Hilfsfunktionen ---
|
12 |
def calculate_gematria_sum(text):
|
13 |
+
"""
|
14 |
+
Berechnet die Gematria-Summe eines gegebenen Textes.
|
15 |
+
|
16 |
+
Args:
|
17 |
+
text: Der Text, für den die Gematria-Summe berechnet werden soll.
|
18 |
+
|
19 |
+
Returns:
|
20 |
+
Die Gematria-Summe des Textes, oder None, falls der Text leer ist.
|
21 |
+
"""
|
22 |
if text:
|
23 |
text_gematria = calculate_gematria(strip_diacritics(text))
|
24 |
return text_gematria
|
|
|
27 |
|
28 |
def date_to_words(date_string):
|
29 |
"""
|
30 |
+
Konvertiert ein Datum im Format YYYY-MM-DD in die englische Schreibweise des Tages.
|
31 |
|
32 |
Args:
|
33 |
date_string: Ein Datum im Format YYYY-MM-DD.
|
34 |
|
35 |
Returns:
|
36 |
+
Einen String mit der englischen Schreibweise des Tages.
|
37 |
"""
|
38 |
date_obj = datetime.strptime(date_string, "%Y-%m-%d")
|
39 |
return date_obj.strftime("%A")
|
40 |
|
41 |
def perform_gematria_calculation_for_date_range(start_date, end_date):
|
42 |
+
"""
|
43 |
+
Führt die Gematria-Berechnung für einen Datumsbereich durch.
|
44 |
+
|
45 |
+
Args:
|
46 |
+
start_date: Das Startdatum als datetime-Objekt.
|
47 |
+
end_date: Das Enddatum als datetime-Objekt.
|
48 |
+
|
49 |
+
Returns:
|
50 |
+
Ein Dictionary mit den Ergebnissen, gruppiert nach Gematria-Summe.
|
51 |
+
"""
|
52 |
+
logger.info(f"Startdatum: {start_date}, Enddatum: {end_date}")
|
53 |
results = {}
|
54 |
delta = timedelta(days=1)
|
55 |
current_date = start_date
|
|
|
58 |
# Datum in String umwandeln
|
59 |
date_string = current_date.strftime("%Y-%m-%d")
|
60 |
date_words = date_to_words(date_string)
|
61 |
+
logger.info(f"Datum: {current_date}, Tagesname: {date_words}")
|
62 |
gematria_sum = calculate_gematria_sum(date_words)
|
63 |
+
logger.info(f"Gematria-Summe: {gematria_sum}")
|
64 |
|
65 |
if gematria_sum not in results:
|
66 |
results[gematria_sum] = []
|
|
|
75 |
return results
|
76 |
|
77 |
def generate_json_output(results, start_date, end_date):
|
78 |
+
"""
|
79 |
+
Generiert die JSON-Ausgabe mit dem Datumsbereich und den Ergebnissen.
|
80 |
+
|
81 |
+
Args:
|
82 |
+
results: Ein Dictionary mit den Ergebnissen, gruppiert nach Gematria-Summe.
|
83 |
+
start_date: Das Startdatum als datetime-Objekt.
|
84 |
+
end_date: Das Enddatum als datetime-Objekt.
|
85 |
+
|
86 |
+
Returns:
|
87 |
+
Einen JSON-String mit den Ergebnissen.
|
88 |
+
"""
|
89 |
result = {
|
90 |
"DateRange": {
|
91 |
"StartDate": start_date.strftime("%Y-%m-%d"),
|
|
|
95 |
}
|
96 |
return json.dumps(result, indent=4, ensure_ascii=False)
|
97 |
|
98 |
+
# --- Hauptanwendung mit Gradio ---
|
99 |
with gr.Blocks() as app:
|
100 |
with gr.Row():
|
101 |
+
start_date = Calendar(type="datetime", label="Startdatum")
|
102 |
+
end_date = Calendar(type="datetime", label="Enddatum")
|
103 |
|
104 |
+
calculate_btn = gr.Button("Gematria für Zeitraum berechnen")
|
105 |
+
json_output = gr.Textbox(label="JSON-Ausgabe")
|
106 |
|
107 |
+
# --- Event-Handler ---
|
108 |
def perform_calculation(start_date, end_date):
|
109 |
+
"""
|
110 |
+
Führt die Berechnung aus und generiert die JSON-Ausgabe.
|
111 |
+
|
112 |
+
Args:
|
113 |
+
start_date: Das Startdatum als datetime-Objekt.
|
114 |
+
end_date: Das Enddatum als datetime-Objekt.
|
115 |
+
|
116 |
+
Returns:
|
117 |
+
Den JSON-String mit den Ergebnissen.
|
118 |
+
"""
|
119 |
logger.info(f"perform_calculation aufgerufen mit: start_date={start_date}, end_date={end_date}")
|
120 |
results = perform_gematria_calculation_for_date_range(start_date, end_date)
|
121 |
json_result = generate_json_output(results, start_date, end_date)
|
122 |
return json_result
|
123 |
|
124 |
+
# --- Event-Trigger ---
|
125 |
calculate_btn.click(
|
126 |
perform_calculation,
|
127 |
inputs=[start_date, end_date],
|