diff --git a/app.py b/app.py index ba59a97..afe43a3 100644 --- a/app.py +++ b/app.py @@ -6,25 +6,31 @@ import sqlite3 import string # for literals import json # for dictionary import hunspell # for spell checking -DEBUG = 2 +DEBUG = 0 """ To-do: +Separate dictionary-dictionary for hunsepll +Search phrase alias +Response Bible book reading +Search highlighting Styles Bible Reading Plan -Bible Viewer +Bible Reader """ def dbg(message): - # if DEBUG is at or above a value of one, a call from debug level one will print red if DEBUG >= 1: print(f'\033[91m{message}\033[0m') def dbg2(message): - # if DEBUG is at or above a value of two, a call from debug level one will print green if DEBUG >= 2: - print(f'\033[32m{message}\033[0m') + 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") dictionary_json = "data/1828_Webster_KJV.json" kjv_cur = sqlite3.connect("data/kjv.db").cursor() @@ -40,31 +46,32 @@ idx_verse = 3 idx_text = 4 def lookup_one_verse(verse_id): - dbg("lookup_one_verse({})".format(verse_id)) + dbg2("lookup_one_verse({})".format(verse_id)) return(kjv_cur.execute("SELECT * FROM fts_kjv WHERE id = {};".format(verse_id)).fetchone()) def lookup_bookname(book_id): - dbg2("lookup_bookname({})".format(book_id)) + dbg3("lookup_bookname({})".format(book_id)) result = kjv_cur.execute("SELECT n FROM key_english WHERE b = {};".format(book_id)).fetchone() if result: result = result[0] - dbg("lookup_bookname.result = '{}'".format(result)) + dbg2("lookup_bookname.result = '{}'".format(result)) return result def lookup_book_id(bookname): - dbg2("lookup_book_id({})".format(bookname)) + dbg3("lookup_book_id({})".format(bookname)) result = kjv_cur.execute("SELECT b FROM key_english WHERE n = '{}';".format(bookname)).fetchone() if result: result = result[0] - dbg2("lookup_book_id.result = '{}'".format(result)) + dbg3("lookup_book_id.result = '{}'".format(result)) return result def lookup_fts(kwds): + dbg3("lookup_fts.kwds = '{}'".format(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() - dbg("lookup_contains({}) {} results".format(kw,len(results))) + dbg2("lookup_contains({}) {} results".format(kw,len(results))) return results def lookup_by_verse_id(start_verse, end_verse = None): @@ -110,16 +117,18 @@ def lookup_contains_exact(kw): def ref_input_cleaning(ref, valid_chars=(string.ascii_letters + string.digits + ":-,")): dbg2("ref_input_cleaning({})".format(ref)) - ref = list(ref.replace(" ","")) + ref = ref.replace(" ","") if ref.count(':') != 1: dbg2("ref_input_cleaning.if ref.count(:): TRUE") - return False + dbg2(" -> Assuming user wanted entire chapter") + ref += ":-" if ref.count("-") > 1: dbg2("ref_input_cleaning.if ref.count(-): TRUE") return False if not ref[-1].isdigit() and ref[-1] != '-': dbg2("ref_input_cleaning.if ref[-1] TRUE") return False + ref = list(ref) # preserve book number if we can guess the first # character is a number and 3nd is a letter if ref[0].isdigit() and ref[1].isalpha(): @@ -149,6 +158,30 @@ def ref_parse_book(ref): return book return False +@app.get("/find") +def parse_query(): + query = request.args.get("kw", None) + if not query: + return send_file("html/find.html") + result = show() + if not hasattr(result, '__len__'): + dbg3("parse_query.show = '{}'".format(result)) + return result + + if len(result) > 17: + return result + result = '' + if len(query.split()) == 1: + result += "