blackened formatting
This commit is contained in:
@@ -6,6 +6,7 @@ import sqlite3
|
|||||||
import string # for literals
|
import string # for literals
|
||||||
import json # for dictionary
|
import json # for dictionary
|
||||||
import hunspell # for spell checking
|
import hunspell # for spell checking
|
||||||
|
|
||||||
DEBUG = 0
|
DEBUG = 0
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -19,15 +20,22 @@ Bible Reading Plan
|
|||||||
Bible Reader
|
Bible Reader
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def dbg(message):
|
def dbg(message):
|
||||||
if DEBUG >= 1:
|
if DEBUG >= 1:
|
||||||
print(f'\033[91m{message}\033[0m')
|
print(f"\033[91m{message}\033[0m")
|
||||||
|
|
||||||
|
|
||||||
def dbg2(message):
|
def dbg2(message):
|
||||||
if DEBUG >= 2:
|
if DEBUG >= 2:
|
||||||
print(f' \033[32m{message}\033[0m')
|
print(f" \033[32m{message}\033[0m")
|
||||||
|
|
||||||
|
|
||||||
def dbg3(message):
|
def dbg3(message):
|
||||||
if DEBUG >= 3:
|
if DEBUG >= 3:
|
||||||
print(f' \033[35m{message}\033[0m')
|
print(f" \033[35m{message}\033[0m")
|
||||||
|
|
||||||
|
|
||||||
dbg("Debug Level 1 Enabled")
|
dbg("Debug Level 1 Enabled")
|
||||||
dbg2("Debug Level 2 Enabled")
|
dbg2("Debug Level 2 Enabled")
|
||||||
dbg3("Debug Level 3 Enabled")
|
dbg3("Debug Level 3 Enabled")
|
||||||
@@ -45,40 +53,60 @@ idx_chapter = 2
|
|||||||
idx_verse = 3
|
idx_verse = 3
|
||||||
idx_text = 4
|
idx_text = 4
|
||||||
|
|
||||||
|
|
||||||
def lookup_one_verse(verse_id):
|
def lookup_one_verse(verse_id):
|
||||||
dbg2("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())
|
return kjv_cur.execute(
|
||||||
|
"SELECT * FROM fts_kjv WHERE id = {};".format(verse_id)
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
|
||||||
def lookup_bookname(book_id):
|
def lookup_bookname(book_id):
|
||||||
dbg3("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()
|
result = kjv_cur.execute(
|
||||||
|
"SELECT n FROM key_english WHERE b = {};".format(book_id)
|
||||||
|
).fetchone()
|
||||||
if result:
|
if result:
|
||||||
result = result[0]
|
result = result[0]
|
||||||
dbg2("lookup_bookname.result = '{}'".format(result))
|
dbg2("lookup_bookname.result = '{}'".format(result))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def lookup_book_id(bookname):
|
def lookup_book_id(bookname):
|
||||||
dbg3("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()
|
result = kjv_cur.execute(
|
||||||
|
"SELECT b FROM key_english WHERE n = '{}';".format(bookname)
|
||||||
|
).fetchone()
|
||||||
if result:
|
if result:
|
||||||
result = result[0]
|
result = result[0]
|
||||||
dbg3("lookup_book_id.result = '{}'".format(result))
|
dbg3("lookup_book_id.result = '{}'".format(result))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def lookup_fts(kwds):
|
def lookup_fts(kwds):
|
||||||
dbg3("lookup_fts.kwds = '{}'".format(kwds))
|
dbg3("lookup_fts.kwds = '{}'".format(kwds))
|
||||||
return kjv_cur.execute("SELECT * FROM fts_kjv('{}')".format(kwds)).fetchall()
|
return kjv_cur.execute("SELECT * FROM fts_kjv('{}')".format(kwds)).fetchall()
|
||||||
|
|
||||||
|
|
||||||
def lookup_contains(kw):
|
def lookup_contains(kw):
|
||||||
results = kjv_cur.execute("SELECT * FROM fts_kjv WHERE t LIKE '%{}%';".format(kw)).fetchall()
|
results = kjv_cur.execute(
|
||||||
dbg2("lookup_contains({}) {} results".format(kw,len(results)))
|
"SELECT * FROM fts_kjv WHERE t LIKE '%{}%';".format(kw)
|
||||||
|
).fetchall()
|
||||||
|
dbg2("lookup_contains({}) {} results".format(kw, len(results)))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def lookup_by_verse_id(start_verse, end_verse = None):
|
|
||||||
|
def lookup_by_verse_id(start_verse, end_verse=None):
|
||||||
if not end_verse:
|
if not end_verse:
|
||||||
results = kjv_cur.execute("SELECT * FROM fts_kjv WHERE id = {};".format(start_verse)).fetchall()
|
results = kjv_cur.execute(
|
||||||
|
"SELECT * FROM fts_kjv WHERE id = {};".format(start_verse)
|
||||||
|
).fetchall()
|
||||||
else:
|
else:
|
||||||
results = kjv_cur.execute("SELECT * FROM fts_kjv WHERE id BETWEEN {} AND {};".format(start_verse, end_verse)).fetchall()
|
results = kjv_cur.execute(
|
||||||
|
"SELECT * FROM fts_kjv WHERE id BETWEEN {} AND {};".format(
|
||||||
|
start_verse, end_verse
|
||||||
|
)
|
||||||
|
).fetchall()
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
@@ -86,13 +114,14 @@ def get_verse_id(book_id, chapter, verse):
|
|||||||
# verse_id is 00000000 (00 000 000) (book + chapter + verse)
|
# verse_id is 00000000 (00 000 000) (book + chapter + verse)
|
||||||
chapterid = chapter.zfill(3)
|
chapterid = chapter.zfill(3)
|
||||||
verseid = verse.zfill(3)
|
verseid = verse.zfill(3)
|
||||||
return str(book_id)+chapterid+verseid
|
return str(book_id) + chapterid + verseid
|
||||||
|
|
||||||
|
|
||||||
def check_lone_word(text, kw):
|
def check_lone_word(text, kw):
|
||||||
kw_length = len(kw)
|
kw_length = len(kw)
|
||||||
kw_location = text.find(kw)
|
kw_location = text.find(kw)
|
||||||
try:
|
try:
|
||||||
if (text[kw_location-1]).isalpha():
|
if (text[kw_location - 1]).isalpha():
|
||||||
return False
|
return False
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# If it's an indexerror, it's likely that
|
# If it's an indexerror, it's likely that
|
||||||
@@ -100,32 +129,34 @@ def check_lone_word(text, kw):
|
|||||||
# of the text.
|
# of the text.
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
if (text[kw_location+kw_length]).isalpha():
|
if (text[kw_location + kw_length]).isalpha():
|
||||||
return False
|
return False
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def lookup_contains_exact(kw):
|
def lookup_contains_exact(kw):
|
||||||
preresult = lookup_contains(kw)
|
preresult = lookup_contains(kw)
|
||||||
results = []
|
results = []
|
||||||
for result in preresult:
|
for result in preresult:
|
||||||
if check_lone_word(result[idx_text], kw):
|
if check_lone_word(result[idx_text], kw):
|
||||||
results.append(result)
|
results.append(result)
|
||||||
dbg("lookup_contains({}) {} results".format(kw,len(results)))
|
dbg("lookup_contains({}) {} results".format(kw, len(results)))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def ref_input_cleaning(ref, valid_chars=(string.ascii_letters + string.digits + ":-,")):
|
def ref_input_cleaning(ref, valid_chars=(string.ascii_letters + string.digits + ":-,")):
|
||||||
dbg2("ref_input_cleaning({})".format(ref))
|
dbg2("ref_input_cleaning({})".format(ref))
|
||||||
ref = ref.replace(" ","")
|
ref = ref.replace(" ", "")
|
||||||
if ref.count(':') != 1:
|
if ref.count(":") != 1:
|
||||||
dbg2("ref_input_cleaning.if ref.count(:): TRUE")
|
dbg2("ref_input_cleaning.if ref.count(:): TRUE")
|
||||||
dbg2(" -> Assuming user wanted entire chapter")
|
dbg2(" -> Assuming user wanted entire chapter")
|
||||||
ref += ":-"
|
ref += ":-"
|
||||||
if ref.count("-") > 1:
|
if ref.count("-") > 1:
|
||||||
dbg2("ref_input_cleaning.if ref.count(-): TRUE")
|
dbg2("ref_input_cleaning.if ref.count(-): TRUE")
|
||||||
return False
|
return False
|
||||||
if not ref[-1].isdigit() and ref[-1] != '-':
|
if not ref[-1].isdigit() and ref[-1] != "-":
|
||||||
dbg2("ref_input_cleaning.if ref[-1] TRUE")
|
dbg2("ref_input_cleaning.if ref[-1] TRUE")
|
||||||
return False
|
return False
|
||||||
ref = list(ref)
|
ref = list(ref)
|
||||||
@@ -134,7 +165,7 @@ def ref_input_cleaning(ref, valid_chars=(string.ascii_letters + string.digits +
|
|||||||
if ref[0].isdigit() and ref[1].isalpha():
|
if ref[0].isdigit() and ref[1].isalpha():
|
||||||
prefix = ref.pop(0) + " "
|
prefix = ref.pop(0) + " "
|
||||||
else:
|
else:
|
||||||
prefix = ''
|
prefix = ""
|
||||||
# clean the rest of the reference
|
# clean the rest of the reference
|
||||||
cleaned_ref = []
|
cleaned_ref = []
|
||||||
for character in ref:
|
for character in ref:
|
||||||
@@ -143,14 +174,18 @@ def ref_input_cleaning(ref, valid_chars=(string.ascii_letters + string.digits +
|
|||||||
# Was there a problem?
|
# Was there a problem?
|
||||||
if len(cleaned_ref) == 0:
|
if len(cleaned_ref) == 0:
|
||||||
return False
|
return False
|
||||||
return prefix + ''.join(cleaned_ref).capitalize()
|
return prefix + "".join(cleaned_ref).capitalize()
|
||||||
|
|
||||||
def search_input_cleaning(query, valid_chars=string.ascii_letters + string.digits + "+^\" "):
|
|
||||||
|
def search_input_cleaning(
|
||||||
|
query, valid_chars=string.ascii_letters + string.digits + '+^" '
|
||||||
|
):
|
||||||
cleaned_query = []
|
cleaned_query = []
|
||||||
for character in query:
|
for character in query:
|
||||||
if character in valid_chars:
|
if character in valid_chars:
|
||||||
cleaned_query.append(character)
|
cleaned_query.append(character)
|
||||||
return ''.join(cleaned_query)
|
return "".join(cleaned_query)
|
||||||
|
|
||||||
|
|
||||||
def ref_parse_book(ref):
|
def ref_parse_book(ref):
|
||||||
for book in reversed(book_names):
|
for book in reversed(book_names):
|
||||||
@@ -158,67 +193,78 @@ def ref_parse_book(ref):
|
|||||||
return book
|
return book
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@app.get("/find")
|
@app.get("/find")
|
||||||
def parse_query():
|
def parse_query():
|
||||||
query = request.args.get("kw", None)
|
query = request.args.get("kw", None)
|
||||||
if not query:
|
if not query:
|
||||||
return send_file("html/find.html")
|
return send_file("html/find.html")
|
||||||
result = show()
|
result = show()
|
||||||
if not hasattr(result, '__len__'):
|
if not hasattr(result, "__len__"):
|
||||||
dbg3("parse_query.show = '{}'".format(result))
|
dbg3("parse_query.show = '{}'".format(result))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
if len(result) > 17:
|
if len(result) > 17:
|
||||||
return result
|
return result
|
||||||
result = ''
|
result = ""
|
||||||
if len(query.split()) == 1:
|
if len(query.split()) == 1:
|
||||||
result += "<!DOCTYPE html><style>"
|
result += "<!DOCTYPE html><style>"
|
||||||
result += open("styles/collapsible.css", 'r').read()
|
result += open("styles/collapsible.css", "r").read()
|
||||||
result += "</style><button type='button' class='collapsible'>See Definition</button><div class='content'>"
|
result += "</style><button type='button' class='collapsible'>See Definition</button><div class='content'>"
|
||||||
result += define() + "</div><script>"
|
result += define() + "</div><script>"
|
||||||
result += open("js/collapsible.js", 'r').read() + "</script>"
|
result += open("js/collapsible.js", "r").read() + "</script>"
|
||||||
dbg3("parse_query.define = '{}'".format(result))
|
dbg3("parse_query.define = '{}'".format(result))
|
||||||
result += search()
|
result += search()
|
||||||
dbg3("parse_query.search = '{}'".format(result))
|
dbg3("parse_query.search = '{}'".format(result))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@app.get("/define")
|
@app.get("/define")
|
||||||
def define():
|
def define():
|
||||||
ref = request.args.get("kw", None)
|
ref = request.args.get("kw", None)
|
||||||
if ref: ref = ref.strip()
|
if ref:
|
||||||
|
ref = ref.strip()
|
||||||
if not ref:
|
if not ref:
|
||||||
return send_file("html/dictionary.html")
|
return send_file("html/dictionary.html")
|
||||||
with open(dictionary_json, 'r') as data:
|
with open(dictionary_json, "r") as data:
|
||||||
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("data/kjv.dic","data/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)
|
||||||
if arg_view == "plain":
|
if arg_view == "plain":
|
||||||
response = return_dict_plain(ref, dictionary[ref])
|
response = return_dict_plain(ref, dictionary[ref])
|
||||||
elif arg_view == "rich":
|
elif arg_view == "rich":
|
||||||
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):
|
||||||
response = ''
|
response = ""
|
||||||
for e in defs:
|
for e in defs:
|
||||||
response += e + "<br><br>"
|
response += e + "<br><br>"
|
||||||
return ref.capitalize() + "<br><br>" + response + "\n"
|
return ref.capitalize() + "<br><br>" + response + "\n"
|
||||||
|
|
||||||
|
|
||||||
def return_dict_rich(ref, defs):
|
def return_dict_rich(ref, defs):
|
||||||
header = open('html/header.html', 'r')
|
header = open("html/header.html", "r")
|
||||||
css = open('styles/human_readable.css', 'r')
|
css = open("styles/human_readable.css", "r")
|
||||||
response_html = open('html/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 (header.read() + response_html.read().format(passage = ref.capitalize(), text = response) + css.read())
|
# return (header.read() + response_html.read().format(passage = ref.capitalize(), text = response) + css.read())
|
||||||
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")
|
||||||
def show():
|
def show():
|
||||||
@@ -227,28 +273,31 @@ def show():
|
|||||||
return send_file("html/show.html")
|
return send_file("html/show.html")
|
||||||
dbg("show({})".format(ref))
|
dbg("show({})".format(ref))
|
||||||
refs = []
|
refs = []
|
||||||
for r in ref.split(','):
|
for r in ref.split(","):
|
||||||
r_ = ref_input_cleaning(r.strip())
|
r_ = ref_input_cleaning(r.strip())
|
||||||
if r_:
|
if r_:
|
||||||
refs.append(r_)
|
refs.append(r_)
|
||||||
if not refs:
|
if not refs:
|
||||||
return("Invalid Query")
|
return "Invalid Query"
|
||||||
verse_results = []
|
verse_results = []
|
||||||
#check if the search is for multiple refs
|
# check if the search is for multiple refs
|
||||||
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("-"):
|
||||||
start_verse = ref_verse.split("-")[0]
|
start_verse = ref_verse.split("-")[0]
|
||||||
end_verse = '500' # just get all the verses if it ends with a dash
|
end_verse = "500" # just get all the verses if it ends with a dash
|
||||||
else:
|
else:
|
||||||
start_verse, end_verse = ref_verse.split("-")[0], ref_verse.split("-")[1]
|
start_verse, end_verse = (
|
||||||
|
ref_verse.split("-")[0],
|
||||||
|
ref_verse.split("-")[1],
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
start_verse = ref_verse
|
start_verse = ref_verse
|
||||||
end_verse = None
|
end_verse = None
|
||||||
@@ -257,7 +306,7 @@ def show():
|
|||||||
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("Invalid Query")
|
return "Invalid Query"
|
||||||
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)
|
||||||
@@ -284,85 +333,97 @@ def response_dict(scripture):
|
|||||||
"verse": scripture[idx_verse],
|
"verse": scripture[idx_verse],
|
||||||
"text": scripture[idx_text],
|
"text": scripture[idx_text],
|
||||||
}
|
}
|
||||||
return (verse)
|
return verse
|
||||||
|
|
||||||
|
|
||||||
def response_text(scripture):
|
def response_text(scripture):
|
||||||
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])
|
||||||
return (bookname + " " + chapter + ":" + verse + " " + text + "\n")
|
return bookname + " " + chapter + ":" + verse + " " + text + "\n"
|
||||||
|
|
||||||
|
|
||||||
def response_rich(scripture):
|
def response_rich(scripture):
|
||||||
css = open('styles/human_readable.css', 'r')
|
css = open("styles/human_readable.css", "r")
|
||||||
response_html = open('html/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):
|
||||||
dbg2("response_single({})".format(scripture))
|
dbg2("response_single({})".format(scripture))
|
||||||
arg_view = request.args.get("view", 'json')
|
arg_view = request.args.get("view", "json")
|
||||||
dbg("->requested_format = {}".format(arg_view))
|
dbg("->requested_format = {}".format(arg_view))
|
||||||
if arg_view == "plain":
|
if arg_view == "plain":
|
||||||
return(response_text(scripture))
|
return response_text(scripture)
|
||||||
elif arg_view == "rich":
|
elif arg_view == "rich":
|
||||||
header = open('html/header.html', 'r')
|
header = open("html/header.html", "r")
|
||||||
return(header.read() + response_rich(scripture))
|
return header.read() + response_rich(scripture)
|
||||||
else:
|
else:
|
||||||
response = response_dict(scripture)
|
response = response_dict(scripture)
|
||||||
return jsonify(response)
|
return jsonify(response)
|
||||||
|
|
||||||
|
|
||||||
def response_multi(scriptures):
|
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))
|
||||||
elif arg_view == "rich":
|
elif arg_view == "rich":
|
||||||
response.append(open('html/header.html', 'r').read())
|
response.append(open("html/header.html", "r").read())
|
||||||
for scripture in scriptures:
|
for scripture in scriptures:
|
||||||
response.append(response_rich(scripture))
|
response.append(response_rich(scripture))
|
||||||
else:
|
else:
|
||||||
for scripture in scriptures:
|
for scripture in scriptures:
|
||||||
response.append(response_dict(scripture))
|
response.append(response_dict(scripture))
|
||||||
return(response)
|
return response
|
||||||
|
|
||||||
|
|
||||||
@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."
|
||||||
|
}
|
||||||
return jsonify(message)
|
return jsonify(message)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
def idx():
|
def idx():
|
||||||
return send_file("html/index.html")
|
return send_file("html/index.html")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/salvation")
|
@app.get("/salvation")
|
||||||
def salvation():
|
def salvation():
|
||||||
return send_file("html/heaven.html")
|
return send_file("html/heaven.html")
|
||||||
|
|
||||||
#backwards-compatibility
|
|
||||||
@app.get('/t/random', defaults={'view':'plain'})
|
# backwards-compatibility
|
||||||
@app.get('/random')
|
@app.get("/t/random", defaults={"view": "plain"})
|
||||||
|
@app.get("/random")
|
||||||
def random_verse():
|
def random_verse():
|
||||||
rand_id = random.SystemRandom().choice(verse_ids)
|
rand_id = random.SystemRandom().choice(verse_ids)
|
||||||
scripture = lookup_one_verse(rand_id)
|
scripture = lookup_one_verse(rand_id)
|
||||||
return(response_single(scripture))
|
return response_single(scripture)
|
||||||
|
|
||||||
#backwards-compatibility
|
|
||||||
@app.get('/t/votd', defaults={'view':'plain'})
|
# backwards-compatibility
|
||||||
@app.get('/votd')
|
@app.get("/t/votd", defaults={"view": "plain"})
|
||||||
|
@app.get("/votd")
|
||||||
def verse_of_the_day():
|
def verse_of_the_day():
|
||||||
today = int(str(date.today()).replace('-',''))
|
today = int(str(date.today()).replace("-", ""))
|
||||||
#this is deterministic because of today's date being used as the seed
|
# this is deterministic because of today's date being used as the seed
|
||||||
random.seed(today)
|
random.seed(today)
|
||||||
scripture = lookup_one_verse(random.choice(verse_ids))
|
scripture = lookup_one_verse(random.choice(verse_ids))
|
||||||
return(response_single(scripture))
|
return response_single(scripture)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/search")
|
@app.get("/search")
|
||||||
def search():
|
def search():
|
||||||
@@ -376,9 +437,11 @@ def search():
|
|||||||
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("data/kjv.dic","data/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":
|
||||||
@@ -388,6 +451,7 @@ def search():
|
|||||||
dbg2("Search Response: {}".format(response))
|
dbg2("Search Response: {}".format(response))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@app.get("/reader")
|
@app.get("/reader")
|
||||||
def bible_reader():
|
def bible_reader():
|
||||||
return send_file("html/reader.html")
|
return send_file("html/reader.html")
|
||||||
@@ -399,6 +463,7 @@ def bible_reader():
|
|||||||
# Footer should have next/previous as well.
|
# Footer should have next/previous as well.
|
||||||
# Maybe preliminary theming support
|
# Maybe preliminary theming support
|
||||||
|
|
||||||
|
|
||||||
@app.get("/plan")
|
@app.get("/plan")
|
||||||
def reading_plan():
|
def reading_plan():
|
||||||
return send_file("html/reading_plan.html")
|
return send_file("html/reading_plan.html")
|
||||||
|
|||||||
Reference in New Issue
Block a user