diff --git a/app.py b/app.py index 96ec326..0ea0b9a 100644 --- a/app.py +++ b/app.py @@ -8,6 +8,8 @@ import json # for dictionary import hunspell # for spell checking import sys +app = Flask(__name__) + if "-vvv" in sys.argv: DEBUG = 3 elif "-vv" in sys.argv: @@ -21,10 +23,9 @@ else: Current work prefixed with * TODO: Replace send_file with something that loads headers and nav templates -* Return multiple defintiions for each word in phrase Search phrase alias dictionary Response Bible book reading -Search highlighting +*Search highlighting Styles Bible Reading Plan Bible Reader @@ -32,28 +33,8 @@ Bible Reader /seq Wrap back to Gen 1:1 when you reach the end of Rev /seq Querying what your UID's next verse is going to be /seq Purging old UIDs after a certain period of non-use -Separate common functions into own library """ -def dbg(message): - if DEBUG >= 1: - print(f"\033[91m{message}\033[0m") - - -def dbg2(message): - if DEBUG >= 2: - print(f" \033[32m{message}\033[0m") - - -def dbg3(message): - if DEBUG >= 3: - print(f" \033[35m{message}\033[0m") - - -dbg("Debug Level 1 Enabled") -dbg2("Debug Level 2 Enabled") -dbg3("Debug Level 3 Enabled") - kjv_cur = sqlite3.connect("data/kjv.db").cursor() cached = { @@ -67,14 +48,10 @@ cached = { "js_collapsible":open("js/collapsible.js", "r").read(), } +def build_html_reponse(): + html = '' + return html -app = Flask(__name__) - -idx_id = 0 -idx_book = 1 -idx_chapter = 2 -idx_verse = 3 -idx_text = 4 def lookup_one_verse(verse_id): @@ -111,14 +88,6 @@ def lookup_fts(kwds): return kjv_cur.execute("SELECT * FROM fts_kjv('{}')".format(kwds)).fetchall() -def lookup_contains(kw): - results = kjv_cur.execute( - "SELECT * FROM fts_kjv WHERE t LIKE '%{}%';".format(kw) - ).fetchall() - dbg2("lookup_contains({}) {} results".format(kw, len(results))) - return results - - def lookup_by_verse_id(start_verse, end_verse=None): if not end_verse: results = kjv_cur.execute( @@ -141,36 +110,6 @@ def get_verse_id(book_id, chapter, verse): verseid = "001" # Avoid verse_ids list IndexErrors on :- searches return str(book_id) + chapterid + verseid - -def check_lone_word(text, kw): - kw_length = len(kw) - kw_location = text.find(kw) - try: - if (text[kw_location - 1]).isalpha(): - return False - except IndexError: - # If it's an indexerror, it's likely that - # the keyword is at the end or beginning - # of the text. - pass - try: - if (text[kw_location + kw_length]).isalpha(): - return False - except IndexError: - pass - return True - - -def lookup_contains_exact(kw): - preresult = lookup_contains(kw) - results = [] - for result in preresult: - if check_lone_word(result[idx_text], kw): - results.append(result) - dbg("lookup_contains({}) {} results".format(kw, len(results))) - return results - - def ref_input_cleaning( ref, valid_chars=(string.ascii_letters + string.digits + ":-,"), ref_search=True ): @@ -244,6 +183,8 @@ def parse_query(): result += "" result += "

1828 Webster Definitions

" split_query = query.replace(",", " ").split(" ") + if len(split_query) > 20: + return "Your Query is too long. 20 Words or less." for word in split_query: definition = define(word) if not definition: @@ -288,7 +229,6 @@ def define(word = None): response = jsonify({ref: dictionary[ref]}) return response - def return_dict_plain(ref, defs): response = "" for e in defs: @@ -310,10 +250,10 @@ def return_dict_rich(ref, defs, simple): ) + css ) - @app.get("/show") def show(kw=None, get_start_verse_id=False): ref = request.args.get("kw", None) + get_chapter = request.args.get("all", False) if kw: ref = kw if ref is None: @@ -336,8 +276,8 @@ def show(kw=None, get_start_verse_id=False): if maybedigit.isdigit(): ref_chapter += maybedigit ref_verse = ref.split(":")[1] - if ref.__contains__("-"): - if ref.endswith("-"): + if ref.__contains__("-") or get_chapter: + if ref.endswith("-") or get_chapter: start_verse = ref_verse.split("-")[0] end_verse = "500" # just get all the verses if it ends with a dash else: @@ -379,28 +319,28 @@ def show(kw=None, get_start_verse_id=False): def response_dict(scripture): # used for JSON responses verse = { - "bookname": lookup_bookname(scripture[idx_book]), - "chapter": scripture[idx_chapter], - "verse": scripture[idx_verse], - "text": scripture[idx_text], + "bookname": lookup_bookname(scripture[1]), + "chapter": scripture[2], + "verse": scripture[3], + "text": scripture[4], } return verse def response_text(scripture): - bookname = lookup_bookname(scripture[idx_book]) - chapter = str(scripture[idx_chapter]) - verse = str(scripture[idx_verse]) - text = str(scripture[idx_text]) + bookname = lookup_bookname(scripture[1]) + chapter = str(scripture[2]) + verse = str(scripture[3]) + text = str(scripture[4]) return bookname + " " + chapter + ":" + verse + " " + text + "\n" def response_rich(scripture): # (passage, text) is the html formatting arguments - bookname = lookup_bookname(scripture[idx_book]) - chapter = str(scripture[idx_chapter]) - verse = str(scripture[idx_verse]) - text = str(scripture[idx_text]) + bookname = lookup_bookname(scripture[1]) + chapter = str(scripture[2]) + verse = str(scripture[3]) + text = str(scripture[4]) passage = bookname + " " + chapter + ":" + verse return ( cached['html_response'].format( @@ -602,3 +542,22 @@ def sequential_read(start=0, num=1, uid=None, getuid=False): response = jsonify(response_list) return response + + +def dbg(message): + if DEBUG >= 1: + print(f"\033[91m{message}\033[0m") + + +def dbg2(message): + if DEBUG >= 2: + print(f" \033[32m{message}\033[0m") + + +def dbg3(message): + if DEBUG >= 3: + print(f" \033[35m{message}\033[0m") + +dbg("Debug Level 1 Enabled") +dbg2("Debug Level 2 Enabled") +dbg3("Debug Level 3 Enabled") \ No newline at end of file diff --git a/html/on_reading_bible.html b/html/on_reading_bible.html new file mode 100644 index 0000000..e12f573 --- /dev/null +++ b/html/on_reading_bible.html @@ -0,0 +1,29 @@ +

On Reading the Holy Bible

+ +

A common trap when reading the Bible is relying on external lenses +to look at the Bible through.

+

By external lense, we mean using an external data source such as +a dictionary like the 1828 Websters we provide +as a way to interpret the meaning of scripture.

+

This is wrong!

+ +

How to read the King James Bible

+

When we read the King James Bible, we need to as the following questions:

+
    +
  1. Who is speaking?
  2. +
  3. Who is being spoken to?
  4. +
  5. When is this being spoken?
  6. +
  7. What are the definitions of the words?
  8. +
  9. Is it consistent with the rest of scripture?
  10. +
+ + diff --git a/html/search_bar.html b/html/search_bar.html new file mode 100644 index 0000000..1a5a6ed --- /dev/null +++ b/html/search_bar.html @@ -0,0 +1,5 @@ +
+ + + +