forked from openlp/openlp
More search updates and corrections.
bzr-revno: 291
This commit is contained in:
parent
44216e6a6a
commit
bd510467d5
@ -366,47 +366,57 @@ class BiblePlugin(Plugin, PluginUtils):
|
||||
a=1
|
||||
|
||||
def translate(self, bible, search):
|
||||
print "------"
|
||||
book = ""
|
||||
schapter = ""
|
||||
echapter = ""
|
||||
sverse=""
|
||||
everse=""
|
||||
search.replace(" ", " ")
|
||||
#search = search.replace("v", ":") # allow V or v for verse instead of :
|
||||
#search = search.replace("V", ":") # allow V or v for verse instead of :
|
||||
co = search.find(":")
|
||||
if co == -1: # no : found
|
||||
i = search.rfind(" ")
|
||||
book = search[:i]
|
||||
chapter = search[i:len(search)]
|
||||
hi = chapter.find("-")
|
||||
if hi != -1:
|
||||
schapter= chapter[:hi]
|
||||
echapter= chapter[hi+1:len(chapter)]
|
||||
else:
|
||||
schapter = chapter
|
||||
else: # more complex
|
||||
i = search.find(" ") # find first space (after book name)
|
||||
book = search[:i] # extract book
|
||||
search = search[i:] # remove book from string
|
||||
co = search.find(":") #find first
|
||||
schapter = search[:co] #first chapter is before colon
|
||||
search = search [co+1:] #remove first chapter and colon
|
||||
hi = search.find("-")
|
||||
if hi != -1:
|
||||
sverse= search[:hi]
|
||||
search = search[hi+1:]
|
||||
co = search.find(":")
|
||||
if co != -1:
|
||||
echapter= search[:co]
|
||||
everse = search[co+1:]
|
||||
else:
|
||||
everse = search
|
||||
print search
|
||||
book, rest = self._split_book_from_verses(search)
|
||||
book = book.rstrip()
|
||||
chapters, verses = self._split_chapters_and_verses(rest)
|
||||
print verses
|
||||
chapters = self._split_chapters(chapters)
|
||||
#v = self._split_verses(verses)
|
||||
print "book = " + book
|
||||
print "chapters =" + str(chapters)
|
||||
#print "from =" + str(v)
|
||||
print "to ="
|
||||
self.searchresults = self.biblemanager.get_verse_text(bible, book,int(chapters[0]), int(chapters[1]), 1, 99)
|
||||
else:
|
||||
everse = search
|
||||
if echapter == "":
|
||||
echapter = schapter
|
||||
if sverse == "":
|
||||
sverse = 1
|
||||
if everse == "":
|
||||
everse = 99
|
||||
# print "book = " + book
|
||||
# print "chapter s =" + str(schapter)
|
||||
# print "chapter e =" + str(echapter)
|
||||
# print "verse s =" + str(sverse)
|
||||
# print "verse e =" + str(everse)
|
||||
self.searchresults = self.biblemanager.get_verse_text(bible, book,int(schapter), int(echapter), int(sverse), int(everse))
|
||||
self._display_results(bible)
|
||||
|
||||
def _split_chapters(self, text):
|
||||
txt = text.split("-") # split in to parts
|
||||
print txt , len(txt)
|
||||
if len(txt) == 1:
|
||||
return [text, text]
|
||||
return txt
|
||||
|
||||
def _split_verses(self, text):
|
||||
print text
|
||||
txt = text.split("-") # split in to parts
|
||||
print txt , len(txt)
|
||||
if len(txt) == 1:
|
||||
return [text, text]
|
||||
return txt
|
||||
|
||||
def _split_book_from_verses(self, search):
|
||||
v = search.split(" ") # split in to parts
|
||||
book = ""
|
||||
for i in range (0, len(v) - 1 ): # Join the books back together except last word
|
||||
book += v[i] + " "
|
||||
verse = v[len(v)-1]
|
||||
return book, verse
|
||||
|
||||
def _split_chapters_and_verses(self, verse):
|
||||
verse = verse.lower().replace("v", ":") # allow V or v for verse instead of :
|
||||
c = verse.split(":")
|
||||
if len(c) == 1:
|
||||
return c[0], []
|
||||
return c[0], c[1]
|
||||
|
@ -103,7 +103,7 @@ class BibleDBImpl(BibleCommon):
|
||||
book.abbreviation = bookabbrev
|
||||
session.add(book)
|
||||
session.commit()
|
||||
return book.id
|
||||
return book
|
||||
|
||||
def save_meta(self, key, value):
|
||||
metadata.bind.echo = False
|
||||
|
@ -186,7 +186,7 @@ class BibleManager():
|
||||
Returns the meta data for a given key
|
||||
"""
|
||||
log.debug( "get_meta %s,%s", bible, key)
|
||||
self.bibleDBCache[bible].get_meta(key)
|
||||
return self.bibleDBCache[bible].get_meta(key)
|
||||
|
||||
def get_verse_text(self, bible, bookname, schapter, echapter, sverse, everse = 0 ):
|
||||
"""
|
||||
@ -204,17 +204,14 @@ class BibleManager():
|
||||
if book == None:
|
||||
book = self.bibleDBCache[bible].create_book(bookname, bookabbrev)
|
||||
for chapter in range(schapter, echapter+1):
|
||||
print chapter
|
||||
v = self.bibleDBCache[bible].get_bible_chapter(book.id, chapter)
|
||||
if v == None:
|
||||
try:
|
||||
chaptlist = self.bibleHTTPCache[bible].get_bible_chapter(bible, book.id, bookname, chapter)
|
||||
self.bibleDBCache[bible].create_chapter(book.id, chapter, chaptlist)
|
||||
except :
|
||||
log.error("Errow thrown %s", sys.exc_info()[1])
|
||||
|
||||
|
||||
#log.debug( "Bible Chapter %s", c )
|
||||
# if not c:
|
||||
# self._loadBook(bible,bookid, bookname, bookabbrev)
|
||||
# self._loadChapter(bible, bookid,bookname, schapter)
|
||||
if schapter == echapter:
|
||||
text = self.bibleDBCache[bible].get_bible_text(bookname, schapter, sverse, everse)
|
||||
else:
|
||||
@ -231,24 +228,8 @@ class BibleManager():
|
||||
|
||||
txt = self.bibleDBCache[bible].get_bible_text(bookname, i, start, end)
|
||||
text.extend(txt)
|
||||
print text
|
||||
return text
|
||||
|
||||
def _load_book(self, bible, bookid, bookname, bookabbrev):
|
||||
log.debug( "load_book %s,%s,%s,%s", bible, bookid, bookname, bookabbrev)
|
||||
cl = self.bibleDBCache[bible].get_bible_book(bookname)
|
||||
log.debug( "get bible book %s" , cl)
|
||||
if not cl :
|
||||
self.bibleDBCache[bible].create_book(bookid, bookname, bookabbrev)
|
||||
|
||||
def _loadChapter(self, bible, bookid, bookname, chapter):
|
||||
log.debug( "load_chapter %s,%s,%s,%s", bible, bookid,bookname, chapter)
|
||||
try :
|
||||
chaptlist = self.bibleHTTPCache[bible].get_bible_chapter(bible, bookid,bookname, chapter)
|
||||
self.bibleDBCache[bible].create_chapter(bookname, chapter, chaptlist)
|
||||
except :
|
||||
log.error("Errow thrown %s", sys.exc_info()[1])
|
||||
|
||||
def _is_new_bible(self, name):
|
||||
"""
|
||||
Check cache to see if new bible
|
||||
|
Loading…
Reference in New Issue
Block a user