fixed whitespace bug in show when multiple queries
This commit is contained in:
@@ -6,7 +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 = 2
|
||||||
|
|
||||||
"""
|
"""
|
||||||
To-do:
|
To-do:
|
||||||
@@ -48,7 +48,7 @@ def lookup_bookname(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]
|
||||||
dbg("lookup_bookname: {}".format(result))
|
dbg("lookup_bookname.result = '{}'".format(result))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def lookup_book_id(bookname):
|
def lookup_book_id(bookname):
|
||||||
@@ -56,6 +56,7 @@ def lookup_book_id(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]
|
||||||
|
dbg2("lookup_book_id.result = '{}'".format(result))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def lookup_fts(kwds):
|
def lookup_fts(kwds):
|
||||||
@@ -108,28 +109,23 @@ def lookup_contains_exact(kw):
|
|||||||
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 + ":-,")):
|
||||||
# removed invalid characters, whitespace
|
dbg2("ref_input_cleaning({})".format(ref))
|
||||||
ref = list(ref.replace(" ",""))
|
ref = list(ref.replace(" ",""))
|
||||||
|
|
||||||
# basic validation checks
|
|
||||||
# do we have a valid verse designator?
|
|
||||||
if ref.count(':') != 1:
|
if ref.count(':') != 1:
|
||||||
|
dbg2("ref_input_cleaning.if ref.count(:): TRUE")
|
||||||
return False
|
return False
|
||||||
# are we only checking one range?
|
|
||||||
if ref.count("-") > 1:
|
if ref.count("-") > 1:
|
||||||
|
dbg2("ref_input_cleaning.if ref.count(-): TRUE")
|
||||||
return False
|
return False
|
||||||
# does our argument end in a number or an endrange?
|
|
||||||
if not ref[-1].isdigit() and ref[-1] != '-':
|
if not ref[-1].isdigit() and ref[-1] != '-':
|
||||||
|
dbg2("ref_input_cleaning.if ref[-1] TRUE")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# preserve book number if we can guess the first
|
# preserve book number if we can guess the first
|
||||||
# character is a number and 3nd is a letter
|
# character is a number and 3nd is a letter
|
||||||
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:
|
||||||
@@ -197,14 +193,13 @@ def show():
|
|||||||
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)
|
r_ = ref_input_cleaning(r.strip())
|
||||||
if r_:
|
if r_:
|
||||||
refs.append(r_)
|
refs.append(r_)
|
||||||
if not ref:
|
if not ref:
|
||||||
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
|
||||||
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:]
|
||||||
@@ -287,7 +282,6 @@ def response_single(scripture):
|
|||||||
return jsonify(response)
|
return jsonify(response)
|
||||||
|
|
||||||
def response_multi(scriptures):
|
def response_multi(scriptures):
|
||||||
dbg2("response_multi({})".format(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))
|
||||||
|
|||||||
Reference in New Issue
Block a user