diff --git a/app.py b/app.py index cbf8f05..f70ee5e 100644 --- a/app.py +++ b/app.py @@ -4,6 +4,7 @@ import random from datetime import date # used for daily verse import sqlite3 import string # for literals +import json # for dictionary DEBUG = 0 """ @@ -27,6 +28,7 @@ def dbg2(message): dbg("Debug Level 1 Enabled") dbg2("Debug Level 2 Enabled") +dictionary_json = "1828_Webster_KJV.json" kjv_cur = sqlite3.connect("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()] @@ -147,14 +149,48 @@ def search_input_cleaning(query, valid_chars=string.ascii_letters + string.digit cleaned_query.append(character) return ''.join(cleaned_query) - - def ref_parse_book(ref): for book in reversed(book_names): if book.startswith(ref): return book return False +@app.get("/define") +def define(): + ref = request.args.get("kw", None) + if not ref: + return send_file("html/dictionary.html") + with open(dictionary_json, 'r') as data: + dictionary = json.load(data) + if not ref in dictionary.keys(): + return "{} not found".format(ref) + + 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]) + else: + response = jsonify({ref:dictionary[ref]}) + + return response + +def return_dict_plain(ref, defs): + response = '' + for e in defs: + response += e + "

" + return ref.capitalize() + "

" + response + +def return_dict_rich(ref, defs): + css = open('human_readable.css', 'r') + response_html = open('response.html', 'r') + + response = '' + for e in defs: + response += e + "

" + + return (response_html.read().format(passage = ref.capitalize(), text = response) + css.read()) + @app.get("/show") def show(): ref = request.args.get("kw", "John 3:16") @@ -322,10 +358,8 @@ def search(): cleaned_keywords = search_input_cleaning(keywords) if not cleaned_keywords: return send_file("html/search.html") - #return ("Invalid Query: Special Characters") else: return send_file("html/search.html") - #return ("No Query") results = lookup_fts(cleaned_keywords) response_list = response_multi(results) diff --git a/html/dictionary.html b/html/dictionary.html new file mode 100644 index 0000000..2a49758 --- /dev/null +++ b/html/dictionary.html @@ -0,0 +1,13 @@ +

Bible Dictionary

+
+
+

+ +