diff --git a/app.py b/app.py
index 9073547..ffc2d22 100644
--- a/app.py
+++ b/app.py
@@ -10,12 +10,7 @@ DEBUG = 0
"""
To-do:
-- Add data and function for Webster 1828 dictionary lookup
---https://github.com/DataWar/1828-dictionary
---https://github.com/mnjrupp/Android_SQLite_Dictionary_1828
---https://github.com/gapmiss/kingdom-study-tools-for-obsidian/tree/main/dictionary/
-- Add data and function for Thesaurus to implement fuzzy search
---https://github.com/zaibacu/thesaurus
+Styles
"""
def dbg(message):
@@ -29,8 +24,8 @@ 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()
+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()]
@@ -165,7 +160,7 @@ def define():
dictionary = json.load(data)
ref = ref.lower()
if not ref in dictionary.keys():
- h = hunspell.HunSpell("kjv.dic","kjv.aff")
+ 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)
@@ -175,7 +170,6 @@ def define():
response = return_dict_rich(ref, dictionary[ref])
else:
response = jsonify({ref:dictionary[ref]})
-
return response
def return_dict_plain(ref, defs):
@@ -185,13 +179,11 @@ def return_dict_plain(ref, defs):
return ref.capitalize() + "
" + response
def return_dict_rich(ref, defs):
- css = open('human_readable.css', 'r')
- response_html = open('response.html', 'r')
-
+ css = open('styles/human_readable.css', 'r')
+ response_html = open('html/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")
@@ -206,13 +198,11 @@ def show():
refs = ref.split(',')
for ref in refs:
dbg("show.reference({})".format(ref))
-
maybe_chapter = ref.split(':')[0][3:]
ref_chapter = ''
for maybedigit in maybe_chapter:
if maybedigit.isdigit():
ref_chapter += maybedigit
-
ref_verse = ref.split(':')[1]
if ref.__contains__('-'):
if ref.endswith('-'):
@@ -224,33 +214,26 @@ def show():
start_verse = ref_verse
end_verse = None
end_verse_id = None
-
book_str = ref_input_cleaning(ref, string.ascii_letters)
ref_bookname = ref_parse_book(book_str)
ref_book_id = lookup_book_id(ref_bookname)
if not ref_book_id:
return("Book reference invalid. Ex: 1John3:16")
-
start_verse_id = get_verse_id(ref_book_id, ref_chapter, start_verse)
if end_verse:
end_verse_id = get_verse_id(ref_book_id, ref_chapter, end_verse)
-
dbg2("show.start_verse_id({})".format(start_verse_id))
dbg2("show.end_verse_id({})".format(end_verse_id))
results = lookup_by_verse_id(start_verse_id, end_verse_id)
dbg2("show.results({})".format(results))
-
for result in results:
verse_results.append(result)
-
response_list = response_multi(verse_results)
-
arg_view = request.args.get("view", None)
if arg_view == "plain" or arg_view == "rich":
response = "
".join(response_list)
else:
response = jsonify(response_list)
-
return response
@@ -272,17 +255,14 @@ def response_text(scripture):
return (bookname + " " + chapter + ":" + verse + " " + text)
def response_rich(scripture):
- css = open('human_readable.css', 'r')
- response_html = open('response.html', 'r')
+ css = open('styles/human_readable.css', 'r')
+ response_html = open('html/response.html', 'r')
# (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])
-
passage = (bookname + " " + chapter + ":" + verse)
-
return (response_html.read().format(passage = passage, text = text) + css.read())
def response_single(scripture):
@@ -302,7 +282,6 @@ def response_multi(scriptures):
response = []
arg_view = request.args.get("view", 'json')
dbg("search ->requested_format = {}".format(arg_view))
-
if arg_view == "plain":
for scripture in scriptures:
response.append(response_text(scripture))
@@ -312,16 +291,8 @@ def response_multi(scriptures):
else:
for scripture in scriptures:
response.append(response_dict(scripture))
-
return(response)
-
-def thesarus(word):
- return word
-def dictionary(word):
- return word
-
-
@app.errorhandler(404)
def page_not_found(e):
message = {"error": "You're lost! Isaiah 41:10 - Fear thou not; for I am with thee: be not dismayed; for I am thy God: I will strengthen thee; yea, I will help thee; yea, I will uphold thee with the right hand of my righteousness."}
@@ -329,11 +300,11 @@ def page_not_found(e):
@app.get("/")
def idx():
- return send_file("index.html")
+ return send_file("html/index.html")
@app.get("/salvation")
def salvation():
- return send_file("heaven.html")
+ return send_file("html/heaven.html")
#backwards-compatibility
@app.get('/t/random', defaults={'view':'plain'})
@@ -363,20 +334,16 @@ def search():
return send_file("html/search.html")
else:
return send_file("html/search.html")
-
results = lookup_fts(cleaned_keywords)
if not results:
- h = hunspell.HunSpell("kjv.dic","kjv.aff")
+ h = hunspell.HunSpell("data/kjv.dic","data/kjv.aff")
suggestions = h.suggest(cleaned_keywords)
return "{} not found, try one of the following: {}".format(cleaned_keywords, ', '.join(suggestions))
response_list = response_multi(results)
-
-
arg_view = request.args.get("view", None)
if arg_view == "plain" or arg_view == "rich":
response = "
".join(response_list)
else:
response = jsonify(response_list)
-
dbg2("Search Response: {}".format(response))
return response
diff --git a/1828_Webster_KJV.json b/data/1828_Webster_KJV.json
similarity index 100%
rename from 1828_Webster_KJV.json
rename to data/1828_Webster_KJV.json
diff --git a/kjv.aff b/data/kjv.aff
similarity index 100%
rename from kjv.aff
rename to data/kjv.aff
diff --git a/kjv.db b/data/kjv.db
similarity index 100%
rename from kjv.db
rename to data/kjv.db
diff --git a/kjv.dic b/data/kjv.dic
similarity index 100%
rename from kjv.dic
rename to data/kjv.dic
diff --git a/heaven.html b/html/heaven.html
similarity index 100%
rename from heaven.html
rename to html/heaven.html
diff --git a/index.html b/html/index.html
similarity index 100%
rename from index.html
rename to html/index.html
diff --git a/response.html b/html/response.html
similarity index 100%
rename from response.html
rename to html/response.html
diff --git a/human_readable.css b/styles/human_readable.css
similarity index 100%
rename from human_readable.css
rename to styles/human_readable.css
diff --git a/av1611_dictionary_scraper.py b/tools/av1611_dictionary_scraper.py
similarity index 100%
rename from av1611_dictionary_scraper.py
rename to tools/av1611_dictionary_scraper.py