fixed whitespace bug in show when multiple queries
This commit is contained in:
@@ -6,7 +6,7 @@ import sqlite3
|
||||
import string # for literals
|
||||
import json # for dictionary
|
||||
import hunspell # for spell checking
|
||||
DEBUG = 0
|
||||
DEBUG = 2
|
||||
|
||||
"""
|
||||
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()
|
||||
if result:
|
||||
result = result[0]
|
||||
dbg("lookup_bookname: {}".format(result))
|
||||
dbg("lookup_bookname.result = '{}'".format(result))
|
||||
return result
|
||||
|
||||
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()
|
||||
if result:
|
||||
result = result[0]
|
||||
dbg2("lookup_book_id.result = '{}'".format(result))
|
||||
return result
|
||||
|
||||
def lookup_fts(kwds):
|
||||
@@ -108,28 +109,23 @@ def lookup_contains_exact(kw):
|
||||
return results
|
||||
|
||||
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(" ",""))
|
||||
|
||||
# basic validation checks
|
||||
# do we have a valid verse designator?
|
||||
if ref.count(':') != 1:
|
||||
dbg2("ref_input_cleaning.if ref.count(:): TRUE")
|
||||
return False
|
||||
# are we only checking one range?
|
||||
if ref.count("-") > 1:
|
||||
dbg2("ref_input_cleaning.if ref.count(-): TRUE")
|
||||
return False
|
||||
# does our argument end in a number or an endrange?
|
||||
if not ref[-1].isdigit() and ref[-1] != '-':
|
||||
dbg2("ref_input_cleaning.if ref[-1] TRUE")
|
||||
return False
|
||||
|
||||
|
||||
# preserve book number if we can guess the first
|
||||
# character is a number and 3nd is a letter
|
||||
if ref[0].isdigit() and ref[1].isalpha():
|
||||
prefix = ref.pop(0) + " "
|
||||
else:
|
||||
prefix = ''
|
||||
|
||||
# clean the rest of the reference
|
||||
cleaned_ref = []
|
||||
for character in ref:
|
||||
@@ -197,14 +193,13 @@ def show():
|
||||
dbg("show({})".format(ref))
|
||||
refs = []
|
||||
for r in ref.split(','):
|
||||
r_ = ref_input_cleaning(r)
|
||||
r_ = ref_input_cleaning(r.strip())
|
||||
if r_:
|
||||
refs.append(r_)
|
||||
if not ref:
|
||||
return("Invalid Query")
|
||||
verse_results = []
|
||||
#check if the search is for multiple refs
|
||||
refs = ref.split(',')
|
||||
for ref in refs:
|
||||
dbg("show.reference({})".format(ref))
|
||||
maybe_chapter = ref.split(':')[0][3:]
|
||||
@@ -287,7 +282,6 @@ def response_single(scripture):
|
||||
return jsonify(response)
|
||||
|
||||
def response_multi(scriptures):
|
||||
dbg2("response_multi({})".format(scriptures))
|
||||
response = []
|
||||
arg_view = request.args.get("view", 'json')
|
||||
dbg("search ->requested_format = {}".format(arg_view))
|
||||
|
||||
Reference in New Issue
Block a user