diff --git a/app.py b/app.py
index 4caae25..96ec326 100644
--- a/app.py
+++ b/app.py
@@ -6,23 +6,35 @@ import sqlite3
import string # for literals
import json # for dictionary
import hunspell # for spell checking
+import sys
-DEBUG = 0
+if "-vvv" in sys.argv:
+ DEBUG = 3
+elif "-vv" in sys.argv:
+ DEBUG = 2
+elif "-v" in sys.argv:
+ DEBUG = 1
+else:
+ DEBUG = 0
"""
-To-do:
-Separate dictionary-dictionary for hunsepll
-Search phrase alias
+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
Styles
Bible Reading Plan
Bible Reader
-Rich:
on each comma
-find: handle ending with ,
+/seq Going backwards (works but is buggy, disabled for now)
+/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")
@@ -42,10 +54,19 @@ 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()
-verse_ids = [i[0] for i in kjv_cur.execute("SELECT id FROM fts_kjv;").fetchall()]
-book_names = [i[0] for i in kjv_cur.execute("SELECT n FROM key_english").fetchall()]
+
+cached = {
+"verse_ids":[i[0] for i in kjv_cur.execute("SELECT id FROM fts_kjv;").fetchall()],
+"book_names":[i[0] for i in kjv_cur.execute("SELECT n FROM key_english").fetchall()],
+"json_dictionary":json.load(open("data/1828_Webster_KJV.json", 'r')),
+"html_response":open("html/response.html", "r").read(),
+"html_navbar":open("html/navbar.html", "r").read(),
+"css_response":open("styles/human_readable.css", "r").read(),
+"css_collapsible":open("styles/collapsible.css", "r").read(),
+"js_collapsible":open("js/collapsible.js", "r").read(),
+}
+
app = Flask(__name__)
@@ -189,7 +210,7 @@ def ref_input_cleaning(
def search_input_cleaning(
- query, valid_chars=string.ascii_letters + string.digits + '+^" '
+ query, valid_chars=string.ascii_letters + string.digits + '+^"* '
):
cleaned_query = []
for character in query:
@@ -199,7 +220,7 @@ def search_input_cleaning(
def ref_parse_book(ref):
- for book in reversed(book_names):
+ for book in reversed(cached['book_names']):
if book.startswith(ref):
return book
return False
@@ -210,6 +231,8 @@ def parse_query():
query = request.args.get("kw", None)
if not query:
return send_file("html/find.html")
+ if query.endswith(','):
+ query = query[:-1]
result = show()
if not hasattr(result, "__len__"):
dbg3("parse_query.show = '{}'".format(result))
@@ -217,40 +240,50 @@ def parse_query():
if len(result) > 17:
return result
- result = ""
- if len(query.split()) == 1:
- result += "
"
- result += define() + "
"
- dbg3("parse_query.define = '{}'".format(result))
+ result = ""
+ result += ""
+ result += "
1828 Webster Definitions
"
+ split_query = query.replace(",", " ").split(" ")
+ for word in split_query:
+ definition = define(word)
+ if not definition:
+ continue
+ result += ""
+ result += "
" + definition + "
"
+ dbg3("parse_query.define = '{}'".format(word))
+ result += ""
+ result += ""
result += search()
dbg3("parse_query.search = '{}'".format(result))
return result
@app.get("/define")
-def define():
+def define(word = None):
ref = request.args.get("kw", None)
+ if word:
+ ref = word
if ref:
ref = ref.strip()
if not ref:
return send_file("html/dictionary.html")
- with open(dictionary_json, "r") as data:
- dictionary = json.load(data)
+ dictionary = cached['json_dictionary']
ref = ref.lower()
if not ref in dictionary.keys():
- h = hunspell.HunSpell("data/kjv.dic", "data/kjv.aff")
- suggestions = h.suggest(ref)
- return "{} not found, try one of the following: {}".format(
- ref, ", ".join(suggestions)
- )
+ if word:
+ return False
+ return "{} not found.".format(ref)
+ # search suggestions kind of suck
+ #h = hunspell.HunSpell("data/kjv.dic", "data/kjv.aff")
+ #suggestions = h.suggest(ref)
+ #return "{} not found, try one of the following: {}".format(
+ # ref, ", ".join(suggestions)
+ #)
arg_view = request.args.get("view", None)
if arg_view == "plain":
response = return_dict_plain(ref, dictionary[ref])
elif arg_view == "rich":
- response = return_dict_rich(ref, dictionary[ref])
+ response = return_dict_rich(ref, dictionary[ref], simple=word)
else:
response = jsonify({ref: dictionary[ref]})
return response
@@ -263,18 +296,18 @@ def return_dict_plain(ref, defs):
return ref.capitalize() + "