Small bugfixes. Removed unused code.
This commit is contained in:
@@ -8,6 +8,8 @@ import json # for dictionary
|
|||||||
import hunspell # for spell checking
|
import hunspell # for spell checking
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
if "-vvv" in sys.argv:
|
if "-vvv" in sys.argv:
|
||||||
DEBUG = 3
|
DEBUG = 3
|
||||||
elif "-vv" in sys.argv:
|
elif "-vv" in sys.argv:
|
||||||
@@ -21,10 +23,9 @@ else:
|
|||||||
Current work prefixed with *
|
Current work prefixed with *
|
||||||
TODO:
|
TODO:
|
||||||
Replace send_file with something that loads headers and nav templates
|
Replace send_file with something that loads headers and nav templates
|
||||||
* Return multiple defintiions for each word in phrase
|
|
||||||
Search phrase alias dictionary
|
Search phrase alias dictionary
|
||||||
Response Bible book reading
|
Response Bible book reading
|
||||||
Search highlighting
|
*Search highlighting
|
||||||
Styles
|
Styles
|
||||||
Bible Reading Plan
|
Bible Reading Plan
|
||||||
Bible Reader
|
Bible Reader
|
||||||
@@ -32,28 +33,8 @@ Bible Reader
|
|||||||
/seq Wrap back to Gen 1:1 when you reach the end of Rev
|
/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 Querying what your UID's next verse is going to be
|
||||||
/seq Purging old UIDs after a certain period of non-use
|
/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")
|
|
||||||
|
|
||||||
|
|
||||||
def dbg2(message):
|
|
||||||
if DEBUG >= 2:
|
|
||||||
print(f" \033[32m{message}\033[0m")
|
|
||||||
|
|
||||||
|
|
||||||
def dbg3(message):
|
|
||||||
if DEBUG >= 3:
|
|
||||||
print(f" \033[35m{message}\033[0m")
|
|
||||||
|
|
||||||
|
|
||||||
dbg("Debug Level 1 Enabled")
|
|
||||||
dbg2("Debug Level 2 Enabled")
|
|
||||||
dbg3("Debug Level 3 Enabled")
|
|
||||||
|
|
||||||
kjv_cur = sqlite3.connect("data/kjv.db").cursor()
|
kjv_cur = sqlite3.connect("data/kjv.db").cursor()
|
||||||
|
|
||||||
cached = {
|
cached = {
|
||||||
@@ -67,14 +48,10 @@ cached = {
|
|||||||
"js_collapsible":open("js/collapsible.js", "r").read(),
|
"js_collapsible":open("js/collapsible.js", "r").read(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def build_html_reponse():
|
||||||
|
html = ''
|
||||||
|
return html
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
idx_id = 0
|
|
||||||
idx_book = 1
|
|
||||||
idx_chapter = 2
|
|
||||||
idx_verse = 3
|
|
||||||
idx_text = 4
|
|
||||||
|
|
||||||
|
|
||||||
def lookup_one_verse(verse_id):
|
def lookup_one_verse(verse_id):
|
||||||
@@ -111,14 +88,6 @@ def lookup_fts(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):
|
|
||||||
results = kjv_cur.execute(
|
|
||||||
"SELECT * FROM fts_kjv WHERE t LIKE '%{}%';".format(kw)
|
|
||||||
).fetchall()
|
|
||||||
dbg2("lookup_contains({}) {} results".format(kw, len(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(
|
results = kjv_cur.execute(
|
||||||
@@ -141,36 +110,6 @@ def get_verse_id(book_id, chapter, verse):
|
|||||||
verseid = "001" # Avoid verse_ids list IndexErrors on :- searches
|
verseid = "001" # Avoid verse_ids list IndexErrors on :- searches
|
||||||
return str(book_id) + chapterid + verseid
|
return str(book_id) + chapterid + verseid
|
||||||
|
|
||||||
|
|
||||||
def check_lone_word(text, kw):
|
|
||||||
kw_length = len(kw)
|
|
||||||
kw_location = text.find(kw)
|
|
||||||
try:
|
|
||||||
if (text[kw_location - 1]).isalpha():
|
|
||||||
return False
|
|
||||||
except IndexError:
|
|
||||||
# If it's an indexerror, it's likely that
|
|
||||||
# the keyword is at the end or beginning
|
|
||||||
# of the text.
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
if (text[kw_location + kw_length]).isalpha():
|
|
||||||
return False
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def lookup_contains_exact(kw):
|
|
||||||
preresult = lookup_contains(kw)
|
|
||||||
results = []
|
|
||||||
for result in preresult:
|
|
||||||
if check_lone_word(result[idx_text], kw):
|
|
||||||
results.append(result)
|
|
||||||
dbg("lookup_contains({}) {} results".format(kw, len(results)))
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
def ref_input_cleaning(
|
def ref_input_cleaning(
|
||||||
ref, valid_chars=(string.ascii_letters + string.digits + ":-,"), ref_search=True
|
ref, valid_chars=(string.ascii_letters + string.digits + ":-,"), ref_search=True
|
||||||
):
|
):
|
||||||
@@ -244,6 +183,8 @@ def parse_query():
|
|||||||
result += "<style>" + cached['css_collapsible'] + "</style>"
|
result += "<style>" + cached['css_collapsible'] + "</style>"
|
||||||
result += "<h3>1828 Webster Definitions</h3>"
|
result += "<h3>1828 Webster Definitions</h3>"
|
||||||
split_query = query.replace(",", " ").split(" ")
|
split_query = query.replace(",", " ").split(" ")
|
||||||
|
if len(split_query) > 20:
|
||||||
|
return "Your Query is too long. 20 Words or less."
|
||||||
for word in split_query:
|
for word in split_query:
|
||||||
definition = define(word)
|
definition = define(word)
|
||||||
if not definition:
|
if not definition:
|
||||||
@@ -288,7 +229,6 @@ def define(word = None):
|
|||||||
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:
|
||||||
@@ -310,10 +250,10 @@ def return_dict_rich(ref, defs, simple):
|
|||||||
) + css
|
) + css
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/show")
|
@app.get("/show")
|
||||||
def show(kw=None, get_start_verse_id=False):
|
def show(kw=None, get_start_verse_id=False):
|
||||||
ref = request.args.get("kw", None)
|
ref = request.args.get("kw", None)
|
||||||
|
get_chapter = request.args.get("all", False)
|
||||||
if kw:
|
if kw:
|
||||||
ref = kw
|
ref = kw
|
||||||
if ref is None:
|
if ref is None:
|
||||||
@@ -336,8 +276,8 @@ def show(kw=None, get_start_verse_id=False):
|
|||||||
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__("-") or get_chapter:
|
||||||
if ref.endswith("-"):
|
if ref.endswith("-") or get_chapter:
|
||||||
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:
|
||||||
@@ -379,28 +319,28 @@ def show(kw=None, get_start_verse_id=False):
|
|||||||
def response_dict(scripture):
|
def response_dict(scripture):
|
||||||
# used for JSON responses
|
# used for JSON responses
|
||||||
verse = {
|
verse = {
|
||||||
"bookname": lookup_bookname(scripture[idx_book]),
|
"bookname": lookup_bookname(scripture[1]),
|
||||||
"chapter": scripture[idx_chapter],
|
"chapter": scripture[2],
|
||||||
"verse": scripture[idx_verse],
|
"verse": scripture[3],
|
||||||
"text": scripture[idx_text],
|
"text": scripture[4],
|
||||||
}
|
}
|
||||||
return verse
|
return verse
|
||||||
|
|
||||||
|
|
||||||
def response_text(scripture):
|
def response_text(scripture):
|
||||||
bookname = lookup_bookname(scripture[idx_book])
|
bookname = lookup_bookname(scripture[1])
|
||||||
chapter = str(scripture[idx_chapter])
|
chapter = str(scripture[2])
|
||||||
verse = str(scripture[idx_verse])
|
verse = str(scripture[3])
|
||||||
text = str(scripture[idx_text])
|
text = str(scripture[4])
|
||||||
return bookname + " " + chapter + ":" + verse + " " + text + "\n"
|
return bookname + " " + chapter + ":" + verse + " " + text + "\n"
|
||||||
|
|
||||||
|
|
||||||
def response_rich(scripture):
|
def response_rich(scripture):
|
||||||
# (passage, text) is the html formatting arguments
|
# (passage, text) is the html formatting arguments
|
||||||
bookname = lookup_bookname(scripture[idx_book])
|
bookname = lookup_bookname(scripture[1])
|
||||||
chapter = str(scripture[idx_chapter])
|
chapter = str(scripture[2])
|
||||||
verse = str(scripture[idx_verse])
|
verse = str(scripture[3])
|
||||||
text = str(scripture[idx_text])
|
text = str(scripture[4])
|
||||||
passage = bookname + " " + chapter + ":" + verse
|
passage = bookname + " " + chapter + ":" + verse
|
||||||
return (
|
return (
|
||||||
cached['html_response'].format(
|
cached['html_response'].format(
|
||||||
@@ -602,3 +542,22 @@ def sequential_read(start=0, num=1, uid=None, getuid=False):
|
|||||||
response = jsonify(response_list)
|
response = jsonify(response_list)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def dbg(message):
|
||||||
|
if DEBUG >= 1:
|
||||||
|
print(f"\033[91m{message}\033[0m")
|
||||||
|
|
||||||
|
|
||||||
|
def dbg2(message):
|
||||||
|
if DEBUG >= 2:
|
||||||
|
print(f" \033[32m{message}\033[0m")
|
||||||
|
|
||||||
|
|
||||||
|
def dbg3(message):
|
||||||
|
if DEBUG >= 3:
|
||||||
|
print(f" \033[35m{message}\033[0m")
|
||||||
|
|
||||||
|
dbg("Debug Level 1 Enabled")
|
||||||
|
dbg2("Debug Level 2 Enabled")
|
||||||
|
dbg3("Debug Level 3 Enabled")
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<h2>On Reading the Holy Bible</h2>
|
||||||
|
|
||||||
|
<p>A common trap when reading the Bible is relying on external lenses
|
||||||
|
to look at the Bible through.</p>
|
||||||
|
<p>By external lense, we mean using an external data source such as
|
||||||
|
a dictionary like the 1828 Websters we provide
|
||||||
|
as a way to interpret the meaning of scripture.</p>
|
||||||
|
<p><b>This is wrong!</b></p>
|
||||||
|
|
||||||
|
<h3>How to read the King James Bible</h3>
|
||||||
|
<p>When we read the King James Bible, we need to as the following questions:</p>
|
||||||
|
<ol>
|
||||||
|
<li>Who is speaking?</li>
|
||||||
|
<li>Who is being spoken to?</li>
|
||||||
|
<li>When is this being spoken?</li>
|
||||||
|
<li>What are the definitions of the words?</li>
|
||||||
|
<li>Is it consistent with the rest of scripture?</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html{
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-size: 14pt;
|
||||||
|
width: 768px;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: #547720
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<form action="/find">
|
||||||
|
<input type="text" name="kw">
|
||||||
|
<input type="hidden" name="view" value="rich"">
|
||||||
|
<input type="submit">
|
||||||
|
<form>
|
||||||
Reference in New Issue
Block a user