Spaces:
Runtime error
Runtime error
import logging | |
logging.basicConfig(level=logging.WARNING) | |
logger = logging.getLogger(__name__) | |
import json | |
import argparse | |
import utils | |
from gematria import calculate_gematria, strip_diacritics | |
import torah | |
from datetime import datetime | |
def translate_date_to_words(date): | |
"""Converts a date to words in English.""" | |
if date is None: | |
return "No date selected" | |
date_string = date.strftime("%Y-%m-%d") | |
date_in_words = utils.date_to_words(date_string) | |
return date_in_words | |
def calculate_gematria_sum(text, date_words): | |
"""Calculates the Gematria sum for a text and date words.""" | |
combined_input = f"{text} {date_words}" | |
sum_value = calculate_gematria(strip_diacritics(combined_input)) | |
return sum_value | |
def perform_els_search(start, end, step, rounds, length, strip_spaces, strip_in_braces, strip_diacritics_chk): | |
"""Performs the Equidistant Letter Sequences (ELS) search.""" | |
results = torah.process_json_files(start, end, step, rounds, length, 'en', strip_spaces, strip_in_braces, strip_diacritics) | |
return results | |
def generate_json_dump(start, end, step, rounds, length, strip_spaces, strip_in_braces, strip_diacritics_chk, search_phrase, results): | |
"""Generates the JSON dump with both configuration and results.""" | |
config = { | |
"Start Book": start, | |
"End Book": end, | |
"Step": step, | |
"Rounds": rounds, | |
"Length": length, | |
"Target Language": 'en', | |
"Strip Spaces": strip_spaces, | |
"Strip Text in Braces": strip_in_braces, | |
"Strip Diacritics": strip_diacritics_chk, | |
"Search Phrase": search_phrase | |
} | |
result = { | |
"Configuration": config, | |
"Results": results | |
} | |
return json.dumps(result, indent=4, ensure_ascii=False) | |
def main(): | |
parser = argparse.ArgumentParser(description='CLI tool for ELS search based on date and name/topic.') | |
parser.add_argument('date', type=str, help='Date in YYYY-MM-DD format') | |
parser.add_argument('name_or_topic', type=str, help='Name or topic for Gematria calculation') | |
args = parser.parse_args() | |
try: | |
date_obj = datetime.strptime(args.date, '%Y-%m-%d') | |
except ValueError: | |
print("Invalid date format. Please use YYYY-MM-DD.") | |
exit(1) | |
date_words = translate_date_to_words(date_obj) | |
gematria_sum = calculate_gematria_sum(args.name_or_topic, date_words) | |
# Default ELS search parameters | |
start = 1 | |
end = 39 | |
step = gematria_sum | |
rounds = "1,-1" # Updated rounds value | |
length = 0 | |
strip_spaces = True | |
strip_in_braces = True | |
strip_diacritics_chk = True | |
results = perform_els_search(start, end, step, rounds, length, strip_spaces, strip_in_braces, strip_diacritics_chk) | |
search_phrase = f"{date_words} {args.name_or_topic}" | |
json_output = generate_json_dump(start, end, step, rounds, length, strip_spaces, strip_in_braces, strip_diacritics_chk, search_phrase, results) | |
print(json_output) | |
if __name__ == "__main__": | |
main() |