File size: 3,021 Bytes
38b58bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()