sane file structure
This commit is contained in:
1 parent
8c8cc7b6b5
commit
56d24a9ff9
10 files changed
+11
-44
No files matched your search
@@ -10,12 +10,7 @@ DEBUG = 0
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
To-do:
|
To-do:
|
||||||
- Add data and function for Webster 1828 dictionary lookup
|
Styles
|
||||||
--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
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def dbg(message):
|
def dbg(message):
|
||||||
@@ -29,8 +24,8 @@ def dbg2(message):
|
|||||||
dbg("Debug Level 1 Enabled")
|
dbg("Debug Level 1 Enabled")
|
||||||
dbg2("Debug Level 2 Enabled")
|
dbg2("Debug Level 2 Enabled")
|
||||||
|
|
||||||
dictionary_json = "1828_Webster_KJV.json"
|
dictionary_json = "data/1828_Webster_KJV.json"
|
||||||
kjv_cur = sqlite3.connect("kjv.db").cursor()
|
kjv_cur = sqlite3.connect("data/kjv.db").cursor()
|
||||||
verse_ids = [i[0] for i in kjv_cur.execute("SELECT id FROM fts_kjv;").fetchall()]
|
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()]
|
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)
|
dictionary = json.load(data)
|
||||||
ref = ref.lower()
|
ref = ref.lower()
|
||||||
if not ref in dictionary.keys():
|
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)
|
suggestions = h.suggest(ref)
|
||||||
return "{} not found, try one of the following: {}".format(ref, ', '.join(suggestions))
|
return "{} not found, try one of the following: {}".format(ref, ', '.join(suggestions))
|
||||||
arg_view = request.args.get("view", None)
|
arg_view = request.args.get("view", None)
|
||||||
@@ -175,7 +170,6 @@ def define():
|
|||||||
response = return_dict_rich(ref, dictionary[ref])
|
response = return_dict_rich(ref, dictionary[ref])
|
||||||
else:
|
else:
|
||||||
response = jsonify({ref:dictionary[ref]})
|
response = jsonify({ref:dictionary[ref]})
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def return_dict_plain(ref, defs):
|
def return_dict_plain(ref, defs):
|
||||||
@@ -185,13 +179,11 @@ def return_dict_plain(ref, defs):
|
|||||||
return ref.capitalize() + "<br><br>" + response
|
return ref.capitalize() + "<br><br>" + response
|
||||||
|
|
||||||
def return_dict_rich(ref, defs):
|
def return_dict_rich(ref, defs):
|
||||||
css = open('human_readable.css', 'r')
|
css = open('styles/human_readable.css', 'r')
|
||||||
response_html = open('response.html', 'r')
|
response_html = open('html/response.html', 'r')
|
||||||
|
|
||||||
response = ''
|
response = ''
|
||||||
for e in defs:
|
for e in defs:
|
||||||
response += e + "<br><br>"
|
response += e + "<br><br>"
|
||||||
|
|
||||||
return (response_html.read().format(passage = ref.capitalize(), text = response) + css.read())
|
return (response_html.read().format(passage = ref.capitalize(), text = response) + css.read())
|
||||||
|
|
||||||
@app.get("/show")
|
@app.get("/show")
|
||||||
@@ -206,13 +198,11 @@ def show():
|
|||||||
refs = ref.split(',')
|
refs = ref.split(',')
|
||||||
for ref in refs:
|
for ref in refs:
|
||||||
dbg("show.reference({})".format(ref))
|
dbg("show.reference({})".format(ref))
|
||||||
|
|
||||||
maybe_chapter = ref.split(':')[0][3:]
|
maybe_chapter = ref.split(':')[0][3:]
|
||||||
ref_chapter = ''
|
ref_chapter = ''
|
||||||
for maybedigit in maybe_chapter:
|
for maybedigit in maybe_chapter:
|
||||||
if maybedigit.isdigit():
|
if maybedigit.isdigit():
|
||||||
ref_chapter += maybedigit
|
ref_chapter += maybedigit
|
||||||
|
|
||||||
ref_verse = ref.split(':')[1]
|
ref_verse = ref.split(':')[1]
|
||||||
if ref.__contains__('-'):
|
if ref.__contains__('-'):
|
||||||
if ref.endswith('-'):
|
if ref.endswith('-'):
|
||||||
@@ -224,33 +214,26 @@ def show():
|
|||||||
start_verse = ref_verse
|
start_verse = ref_verse
|
||||||
end_verse = None
|
end_verse = None
|
||||||
end_verse_id = None
|
end_verse_id = None
|
||||||
|
|
||||||
book_str = ref_input_cleaning(ref, string.ascii_letters)
|
book_str = ref_input_cleaning(ref, string.ascii_letters)
|
||||||
ref_bookname = ref_parse_book(book_str)
|
ref_bookname = ref_parse_book(book_str)
|
||||||
ref_book_id = lookup_book_id(ref_bookname)
|
ref_book_id = lookup_book_id(ref_bookname)
|
||||||
if not ref_book_id:
|
if not ref_book_id:
|
||||||
return("Book reference invalid. Ex: 1John3:16")
|
return("Book reference invalid. Ex: 1John3:16")
|
||||||
|
|
||||||
start_verse_id = get_verse_id(ref_book_id, ref_chapter, start_verse)
|
start_verse_id = get_verse_id(ref_book_id, ref_chapter, start_verse)
|
||||||
if end_verse:
|
if end_verse:
|
||||||
end_verse_id = get_verse_id(ref_book_id, ref_chapter, 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.start_verse_id({})".format(start_verse_id))
|
||||||
dbg2("show.end_verse_id({})".format(end_verse_id))
|
dbg2("show.end_verse_id({})".format(end_verse_id))
|
||||||
results = lookup_by_verse_id(start_verse_id, end_verse_id)
|
results = lookup_by_verse_id(start_verse_id, end_verse_id)
|
||||||
dbg2("show.results({})".format(results))
|
dbg2("show.results({})".format(results))
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
verse_results.append(result)
|
verse_results.append(result)
|
||||||
|
|
||||||
response_list = response_multi(verse_results)
|
response_list = response_multi(verse_results)
|
||||||
|
|
||||||
arg_view = request.args.get("view", None)
|
arg_view = request.args.get("view", None)
|
||||||
if arg_view == "plain" or arg_view == "rich":
|
if arg_view == "plain" or arg_view == "rich":
|
||||||
response = "<br>".join(response_list)
|
response = "<br>".join(response_list)
|
||||||
else:
|
else:
|
||||||
response = jsonify(response_list)
|
response = jsonify(response_list)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@@ -272,17 +255,14 @@ def response_text(scripture):
|
|||||||
return (bookname + " " + chapter + ":" + verse + " " + text)
|
return (bookname + " " + chapter + ":" + verse + " " + text)
|
||||||
|
|
||||||
def response_rich(scripture):
|
def response_rich(scripture):
|
||||||
css = open('human_readable.css', 'r')
|
css = open('styles/human_readable.css', 'r')
|
||||||
response_html = open('response.html', 'r')
|
response_html = open('html/response.html', 'r')
|
||||||
# (passage, text) is the html formatting arguments
|
# (passage, text) is the html formatting arguments
|
||||||
|
|
||||||
bookname = lookup_bookname(scripture[idx_book])
|
bookname = lookup_bookname(scripture[idx_book])
|
||||||
chapter = str(scripture[idx_chapter])
|
chapter = str(scripture[idx_chapter])
|
||||||
verse = str(scripture[idx_verse])
|
verse = str(scripture[idx_verse])
|
||||||
text = str(scripture[idx_text])
|
text = str(scripture[idx_text])
|
||||||
|
|
||||||
passage = (bookname + " " + chapter + ":" + verse)
|
passage = (bookname + " " + chapter + ":" + verse)
|
||||||
|
|
||||||
return (response_html.read().format(passage = passage, text = text) + css.read())
|
return (response_html.read().format(passage = passage, text = text) + css.read())
|
||||||
|
|
||||||
def response_single(scripture):
|
def response_single(scripture):
|
||||||
@@ -302,7 +282,6 @@ def response_multi(scriptures):
|
|||||||
response = []
|
response = []
|
||||||
arg_view = request.args.get("view", 'json')
|
arg_view = request.args.get("view", 'json')
|
||||||
dbg("search ->requested_format = {}".format(arg_view))
|
dbg("search ->requested_format = {}".format(arg_view))
|
||||||
|
|
||||||
if arg_view == "plain":
|
if arg_view == "plain":
|
||||||
for scripture in scriptures:
|
for scripture in scriptures:
|
||||||
response.append(response_text(scripture))
|
response.append(response_text(scripture))
|
||||||
@@ -312,16 +291,8 @@ def response_multi(scriptures):
|
|||||||
else:
|
else:
|
||||||
for scripture in scriptures:
|
for scripture in scriptures:
|
||||||
response.append(response_dict(scripture))
|
response.append(response_dict(scripture))
|
||||||
|
|
||||||
return(response)
|
return(response)
|
||||||
|
|
||||||
|
|
||||||
def thesarus(word):
|
|
||||||
return word
|
|
||||||
def dictionary(word):
|
|
||||||
return word
|
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def page_not_found(e):
|
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."}
|
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("/")
|
@app.get("/")
|
||||||
def idx():
|
def idx():
|
||||||
return send_file("index.html")
|
return send_file("html/index.html")
|
||||||
|
|
||||||
@app.get("/salvation")
|
@app.get("/salvation")
|
||||||
def salvation():
|
def salvation():
|
||||||
return send_file("heaven.html")
|
return send_file("html/heaven.html")
|
||||||
|
|
||||||
#backwards-compatibility
|
#backwards-compatibility
|
||||||
@app.get('/t/random', defaults={'view':'plain'})
|
@app.get('/t/random', defaults={'view':'plain'})
|
||||||
@@ -363,20 +334,16 @@ def search():
|
|||||||
return send_file("html/search.html")
|
return send_file("html/search.html")
|
||||||
else:
|
else:
|
||||||
return send_file("html/search.html")
|
return send_file("html/search.html")
|
||||||
|
|
||||||
results = lookup_fts(cleaned_keywords)
|
results = lookup_fts(cleaned_keywords)
|
||||||
if not results:
|
if not results:
|
||||||
h = hunspell.HunSpell("kjv.dic","kjv.aff")
|
h = hunspell.HunSpell("data/kjv.dic","data/kjv.aff")
|
||||||
suggestions = h.suggest(cleaned_keywords)
|
suggestions = h.suggest(cleaned_keywords)
|
||||||
return "{} not found, try one of the following: {}".format(cleaned_keywords, ', '.join(suggestions))
|
return "{} not found, try one of the following: {}".format(cleaned_keywords, ', '.join(suggestions))
|
||||||
response_list = response_multi(results)
|
response_list = response_multi(results)
|
||||||
|
|
||||||
|
|
||||||
arg_view = request.args.get("view", None)
|
arg_view = request.args.get("view", None)
|
||||||
if arg_view == "plain" or arg_view == "rich":
|
if arg_view == "plain" or arg_view == "rich":
|
||||||
response = "<br>".join(response_list)
|
response = "<br>".join(response_list)
|
||||||
else:
|
else:
|
||||||
response = jsonify(response_list)
|
response = jsonify(response_list)
|
||||||
|
|
||||||
dbg2("Search Response: {}".format(response))
|
dbg2("Search Response: {}".format(response))
|
||||||
return response
|
return response
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user