forked from openlp/openlp
Bug fixes
Changed book handling from name to book_reference_id Comment out unused function to fill the testament table in the local bible database
This commit is contained in:
parent
4071daec18
commit
599e876955
@ -70,7 +70,7 @@ import chardet
|
||||
import csv
|
||||
|
||||
from openlp.core.lib import Receiver, translate
|
||||
from openlp.plugins.bibles.lib.db import BibleDB, Testament, BiblesResourcesDB
|
||||
from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB#, Testament
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -87,13 +87,16 @@ class CSVBible(BibleDB):
|
||||
log.info(self.__class__.__name__)
|
||||
BibleDB.__init__(self, parent, **kwargs)
|
||||
self.parent = parent
|
||||
#TODO: Delete unused code
|
||||
'''
|
||||
try:
|
||||
self.testamentsfile = kwargs[u'testamentsfile']
|
||||
except KeyError:
|
||||
self.testamentsfile = None
|
||||
'''
|
||||
self.booksfile = kwargs[u'booksfile']
|
||||
self.versesfile = kwargs[u'versefile']
|
||||
|
||||
'''
|
||||
def setup_testaments(self):
|
||||
"""
|
||||
Overrides parent method so we can handle importing a testament file.
|
||||
@ -127,7 +130,7 @@ class CSVBible(BibleDB):
|
||||
'BibleDB.Wizard', 'Importing testaments... done.')), 2)
|
||||
else:
|
||||
BibleDB.setup_testaments(self)
|
||||
|
||||
'''
|
||||
def do_import(self):
|
||||
"""
|
||||
Import the bible books and verses.
|
||||
|
@ -48,13 +48,14 @@ class BibleMeta(BaseModel):
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
#TODO: Delete unused code
|
||||
'''
|
||||
class Testament(BaseModel):
|
||||
"""
|
||||
Bible Testaments
|
||||
"""
|
||||
pass
|
||||
|
||||
'''
|
||||
|
||||
class Book(BaseModel):
|
||||
"""
|
||||
@ -89,10 +90,13 @@ def init_schema(url):
|
||||
Column(u'key', types.Unicode(255), primary_key=True, index=True),
|
||||
Column(u'value', types.Unicode(255)),
|
||||
)
|
||||
#TODO: Delete unused code
|
||||
'''
|
||||
testament_table = Table(u'testament', metadata,
|
||||
Column(u'id', types.Integer, primary_key=True),
|
||||
Column(u'name', types.Unicode(50)),
|
||||
)
|
||||
'''
|
||||
book_table = Table(u'book', metadata,
|
||||
Column(u'id', types.Integer, primary_key=True),
|
||||
Column(u'book_reference_id', types.Integer),
|
||||
@ -101,7 +105,8 @@ def init_schema(url):
|
||||
)
|
||||
verse_table = Table(u'verse', metadata,
|
||||
Column(u'id', types.Integer, primary_key=True, index=True),
|
||||
Column(u'book_id', types.Integer, ForeignKey(u'book.id'), index=True),
|
||||
Column(u'book_id', types.Integer, ForeignKey(
|
||||
u'book.id'), index=True),
|
||||
Column(u'chapter', types.Integer, index=True),
|
||||
Column(u'verse', types.Integer, index=True),
|
||||
Column(u'text', types.UnicodeText, index=True),
|
||||
@ -111,10 +116,13 @@ def init_schema(url):
|
||||
class_mapper(BibleMeta)
|
||||
except UnmappedClassError:
|
||||
mapper(BibleMeta, meta_table)
|
||||
#TODO: Delete unused code
|
||||
'''
|
||||
try:
|
||||
class_mapper(Testament)
|
||||
except UnmappedClassError:
|
||||
mapper(Testament, testament_table)
|
||||
'''
|
||||
try:
|
||||
class_mapper(Book)
|
||||
except UnmappedClassError:
|
||||
@ -239,9 +247,12 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
self.wizard = wizard
|
||||
self.create_meta(u'dbversion', u'2')
|
||||
self.setup_testaments()
|
||||
#TODO: Delete unused code
|
||||
#self.setup_testaments()
|
||||
return self.name
|
||||
|
||||
#TODO: Delete unused code
|
||||
'''
|
||||
def setup_testaments(self):
|
||||
"""
|
||||
Initialise the testaments section of a bible with suitable defaults.
|
||||
@ -249,6 +260,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
self.save_object(Testament.populate(name=u'Old Testament'))
|
||||
self.save_object(Testament.populate(name=u'New Testament'))
|
||||
self.save_object(Testament.populate(name=u'Apocrypha'))
|
||||
'''
|
||||
|
||||
def create_book(self, name, bk_ref_id, testament=1):
|
||||
"""
|
||||
@ -264,7 +276,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
*Defaults to 1.* The testament_reference_id from
|
||||
bibles_resources.sqlite of the testament this book belongs to.
|
||||
"""
|
||||
log.debug(u'create_book %s,%s', name, bk_ref_id)
|
||||
log.debug(u'BibleDB.create_book("%s", "%s")', name, bk_ref_id)
|
||||
book = Book.populate(name=name, book_reference_id=bk_ref_id,
|
||||
testament_reference_id=testament)
|
||||
self.save_object(book)
|
||||
@ -284,7 +296,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
A dict of the verses to be inserted. The key is the verse number,
|
||||
and the value is the verse text.
|
||||
"""
|
||||
log.debug(u'create_chapter %s,%s', book_id, chapter)
|
||||
log.debug(u'BibleDBcreate_chapter("%s", "%s")', book_id, chapter)
|
||||
# Text list has book and chapter as first two elements of the array.
|
||||
for verse_number, verse_text in textlist.iteritems():
|
||||
verse = Verse.populate(
|
||||
@ -336,7 +348,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
if not isinstance(value, unicode):
|
||||
value = unicode(value)
|
||||
log.debug(u'save_meta %s/%s', key, value)
|
||||
log.debug(u'BibleDB.save_meta("%s/%s")', key, value)
|
||||
self.save_object(BibleMeta.populate(key=key, value=value))
|
||||
|
||||
def get_book(self, book):
|
||||
@ -346,7 +358,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
``book``
|
||||
The name of the book to return.
|
||||
"""
|
||||
log.debug(u'BibleDb.get_book("%s")', book)
|
||||
log.debug(u'BibleDB.get_book("%s")', book)
|
||||
db_book = self.get_object_filtered(Book, Book.name.like(book + u'%'))
|
||||
return db_book
|
||||
|
||||
@ -361,15 +373,15 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a book object from the database.
|
||||
|
||||
``book``
|
||||
The name of the book to return.
|
||||
``id``
|
||||
The reference id of the book to return.
|
||||
"""
|
||||
log.debug(u'BibleDb.get_book_by_book_ref_id("%s")', id)
|
||||
log.debug(u'BibleDB.get_book_by_book_ref_id("%s")', id)
|
||||
db_book = self.get_object_filtered(Book,
|
||||
Book.book_reference_id.like(id))
|
||||
return db_book
|
||||
|
||||
def get_verses(self, reference_list, en_reference_list):
|
||||
def get_verses(self, reference_list):
|
||||
"""
|
||||
This is probably the most used function. It retrieves the list of
|
||||
verses based on the user's query.
|
||||
@ -378,27 +390,24 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
This is the list of references the media manager item wants. It is
|
||||
a list of tuples, with the following format::
|
||||
|
||||
(book, chapter, start_verse, end_verse)
|
||||
(book_reference_id, chapter, start_verse, end_verse)
|
||||
|
||||
Therefore, when you are looking for multiple items, simply break
|
||||
them up into references like this, bundle them into a list. This
|
||||
function then runs through the list, and returns an amalgamated
|
||||
list of ``Verse`` objects. For example::
|
||||
|
||||
[(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)]
|
||||
[(u'35', 1, 1, 1), (u'35', 2, 2, 3)]
|
||||
"""
|
||||
log.debug(u'BibleDB.get_verses: %s - %s', reference_list,
|
||||
en_reference_list)
|
||||
log.debug(u'BibleDB.get_verses("%s")', reference_list)
|
||||
verse_list = []
|
||||
for (book, chapter, start_verse, end_verse), (en_book, en_chapter,
|
||||
en_start_verse, en_end_verse) in zip(reference_list,
|
||||
en_reference_list):
|
||||
db_book = self.get_book(book)
|
||||
for book_id, chapter, start_verse, end_verse in reference_list:
|
||||
db_book = self.get_book_by_book_ref_id(book_id)
|
||||
if db_book:
|
||||
book = db_book.name
|
||||
log.debug(u'Book name corrected to "%s"', book)
|
||||
book_id = db_book.book_reference_id
|
||||
log.debug(u'Book name corrected to "%s"', db_book.name)
|
||||
if end_verse == -1:
|
||||
end_verse = self.get_verse_count(en_book, chapter)
|
||||
end_verse = self.get_verse_count(book_id, chapter)
|
||||
verses = self.session.query(Verse)\
|
||||
.filter_by(book_id=db_book.id)\
|
||||
.filter_by(chapter=chapter)\
|
||||
@ -443,23 +452,23 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
verses = verses.all()
|
||||
return verses
|
||||
|
||||
def get_chapter_count(self, book):
|
||||
def get_chapter_count(self, book_id):
|
||||
"""
|
||||
Return the number of chapters in a book.
|
||||
|
||||
``book``
|
||||
The book to get the chapter count for.
|
||||
"""
|
||||
log.debug(u'BibleDB.get_chapter_count("%s")', book)
|
||||
log.debug(u'BibleDB.get_chapter_count("%s")', book_id)
|
||||
count = self.session.query(Verse.chapter).join(Book)\
|
||||
.filter(Book.name==book)\
|
||||
.filter(Book.book_reference_id==book_id)\
|
||||
.distinct().count()
|
||||
if not count:
|
||||
return 0
|
||||
else:
|
||||
return count
|
||||
|
||||
def get_verse_count(self, book, chapter):
|
||||
def get_verse_count(self, book_id, chapter):
|
||||
"""
|
||||
Return the number of verses in a chapter.
|
||||
|
||||
@ -469,9 +478,9 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
``chapter``
|
||||
The chapter to get the verse count for.
|
||||
"""
|
||||
log.debug(u'BibleDB.get_verse_count("%s", %s)', book, chapter)
|
||||
log.debug(u'BibleDB.get_verse_count("%s", "%s")', book_id, chapter)
|
||||
count = self.session.query(Verse).join(Book)\
|
||||
.filter(Book.name==book)\
|
||||
.filter(Book.book_reference_id==book_id)\
|
||||
.filter(Verse.chapter==chapter)\
|
||||
.count()
|
||||
if not count:
|
||||
@ -538,6 +547,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a list of all the books of the Bible.
|
||||
"""
|
||||
log.debug(u'BiblesResourcesDB.get_books()')
|
||||
books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, '
|
||||
u'abbreviation, chapters FROM book_reference ORDER BY id')
|
||||
book_list = []
|
||||
@ -559,7 +569,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
``name``
|
||||
The name or abbreviation of the book.
|
||||
"""
|
||||
log.debug(u'get_book: %s', name)
|
||||
log.debug(u'BiblesResourcesDB.get_book("%s")', name)
|
||||
if not isinstance(name, unicode):
|
||||
name = unicode(name)
|
||||
books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, '
|
||||
@ -584,6 +594,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
``id``
|
||||
The id of the book.
|
||||
"""
|
||||
log.debug(u'BiblesResourcesDB.get_book_by_id("%s")', id)
|
||||
if not isinstance(id, int):
|
||||
id = int(id)
|
||||
books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, '
|
||||
@ -601,22 +612,22 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_chapter(name, chapter):
|
||||
def get_chapter(book_id, chapter):
|
||||
"""
|
||||
Return the chapter details for a specific chapter of a book.
|
||||
|
||||
``name``
|
||||
The name or abbreviation of a book.
|
||||
``book_id``
|
||||
The id of a book.
|
||||
|
||||
``chapter``
|
||||
The chapter number.
|
||||
"""
|
||||
if not isinstance(name, int):
|
||||
log.debug(u'BiblesResourcesDB.get_chapter("%s", "%s")', book_id, chapter)
|
||||
if not isinstance(chapter, int):
|
||||
chapter = int(chapter)
|
||||
book = BiblesResourcesDB.get_book(name)
|
||||
chapters = BiblesResourcesDB.run_sql(u'SELECT id, book_reference_id, '
|
||||
u'chapter, verse_count FROM chapters WHERE book_reference_id = ?',
|
||||
(book[u'id'],))
|
||||
(book_id,))
|
||||
if chapters:
|
||||
return {
|
||||
u'id': chapters[chapter-1][0],
|
||||
@ -628,30 +639,33 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_chapter_count(book):
|
||||
def get_chapter_count(book_id):
|
||||
"""
|
||||
Return the number of chapters in a book.
|
||||
|
||||
``book``
|
||||
The name or abbreviation of the book.
|
||||
``book_id``
|
||||
The id of the book.
|
||||
"""
|
||||
details = BiblesResourcesDB.get_book(book)
|
||||
log.debug(u'BiblesResourcesDB.get_chapter_count("%s")', book_id)
|
||||
details = BiblesResourcesDB.get_book_by_id(book_id)
|
||||
if details:
|
||||
return details[u'chapters']
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def get_verse_count(book, chapter):
|
||||
def get_verse_count(book_id, chapter):
|
||||
"""
|
||||
Return the number of verses in a chapter.
|
||||
|
||||
``book``
|
||||
The name or abbreviation of the book.
|
||||
The id of the book.
|
||||
|
||||
``chapter``
|
||||
The number of the chapter.
|
||||
"""
|
||||
details = BiblesResourcesDB.get_chapter(book, chapter)
|
||||
log.debug(u'BiblesResourcesDB.get_verse_count("%s", "%s")', book_id,
|
||||
chapter)
|
||||
details = BiblesResourcesDB.get_chapter(book_id, chapter)
|
||||
if details:
|
||||
return details[u'verse_count']
|
||||
return 0
|
||||
@ -664,6 +678,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
``name``
|
||||
The name or abbreviation of the book.
|
||||
"""
|
||||
log.debug(u'BiblesResourcesDB.get_download_source("%s")', source)
|
||||
if not isinstance(source, unicode):
|
||||
source = unicode(source)
|
||||
source = source.title()
|
||||
@ -685,6 +700,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
``source``
|
||||
The source of the webbible.
|
||||
"""
|
||||
log.debug(u'BiblesResourcesDB.get_webbibles("%s")', source)
|
||||
if not isinstance(source, unicode):
|
||||
source = unicode(source)
|
||||
source = BiblesResourcesDB.get_download_source(source)
|
||||
@ -716,6 +732,8 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
``source``
|
||||
The source of the webbible.
|
||||
"""
|
||||
log.debug(u'BiblesResourcesDB.get_webbibles("%s", "%s")', abbreviation,
|
||||
source)
|
||||
if not isinstance(abbreviation, unicode):
|
||||
abbreviation = unicode(abbreviation)
|
||||
if not isinstance(source, unicode):
|
||||
@ -742,6 +760,8 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a book_reference_id if the name matches.
|
||||
"""
|
||||
log.debug(u'BiblesResourcesDB.get_spelling("%s", "%s")', name,
|
||||
language_id)
|
||||
if language_id:
|
||||
id = BiblesResourcesDB.run_sql(u'SELECT book_reference_id '
|
||||
u'FROM spelling WHERE name = ? and language_id = ? ORDER BY id',
|
||||
@ -763,6 +783,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
``name``
|
||||
The name or abbreviation of the language.
|
||||
"""
|
||||
log.debug(u'BiblesResourcesDB.get_language("%s", "%s")', name)
|
||||
if not isinstance(name, unicode):
|
||||
name = unicode(name)
|
||||
name = name.title()
|
||||
@ -782,6 +803,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a dict containing all languages with id, name and code.
|
||||
"""
|
||||
log.debug(u'BiblesResourcesDB.get_languages()')
|
||||
languages = BiblesResourcesDB.run_sql(u'SELECT id, name, code FROM '
|
||||
u'language ORDER by name')
|
||||
if languages:
|
||||
@ -801,6 +823,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
Return a list of all testaments and their id of the Bible.
|
||||
"""
|
||||
log.debug(u'BiblesResourcesDB.get_testament_reference()')
|
||||
testaments = BiblesResourcesDB.run_sql(u'SELECT id, name FROM '
|
||||
u'testament_reference ORDER BY id')
|
||||
testament_list = []
|
||||
@ -889,7 +912,7 @@ class SpellingDB(QtCore.QObject, Manager):
|
||||
``language_id``
|
||||
The language which the spelling of the book name is.
|
||||
"""
|
||||
log.debug(u'create_spelling %s, book_reference_id:%s, language_id:%s',
|
||||
log.debug(u'SpellingDBcreate_spelling("%s", "%s", "%s"',
|
||||
name, book_reference_id, language_id)
|
||||
spelling = Spelling.populate(name=name,
|
||||
book_reference_id=book_reference_id, language_id=language_id)
|
||||
|
@ -42,7 +42,7 @@ from openlp.core.lib.ui import critical_error_message_box
|
||||
from openlp.core.utils import AppLocation, get_web_page
|
||||
from openlp.plugins.bibles.lib import SearchResults
|
||||
from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB, \
|
||||
SpellingDB, Book
|
||||
SpellingDB, Book, BibleMeta
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -51,7 +51,7 @@ class BGExtract(object):
|
||||
Extract verses from BibleGateway
|
||||
"""
|
||||
def __init__(self, proxyurl=None):
|
||||
log.debug(u'init %s', proxyurl)
|
||||
log.debug(u'BGExtract.init("%s")', proxyurl)
|
||||
self.proxyurl = proxyurl
|
||||
socket.setdefaulttimeout(30)
|
||||
|
||||
@ -68,9 +68,11 @@ class BGExtract(object):
|
||||
``chapter``
|
||||
Chapter number.
|
||||
"""
|
||||
log.debug(u'get_bible_chapter %s, %s, %s', version, bookname, chapter)
|
||||
log.debug(u'BGExtract.get_bible_chapter("%s", "%s", "%s")', version,
|
||||
bookname, chapter)
|
||||
urlbookname = urllib.quote(bookname.encode("utf-8"))
|
||||
url_params = urllib.urlencode(
|
||||
{u'search': u'%s %s' % (bookname, chapter),
|
||||
{u'search': u'%s %s' % (urlbookname, chapter),
|
||||
u'version': u'%s' % version})
|
||||
cleaner = [(re.compile(' |<br />|\'\+\''), lambda match: '')]
|
||||
soup = get_soup_for_bible_ref(
|
||||
@ -135,7 +137,7 @@ class BGExtract(object):
|
||||
``version``
|
||||
The version of the bible like NIV for New International Version
|
||||
"""
|
||||
log.debug(u'get_books_from_http %s', version)
|
||||
log.debug(u'BGExtract.get_books_from_http("%s")', version)
|
||||
url_params = urllib.urlencode(
|
||||
{u'search': 'Bible-List', u'version': u'%s' % version})
|
||||
reference_url = u'http://www.biblegateway.com/passage/?%s' % url_params
|
||||
@ -161,7 +163,6 @@ class BGExtract(object):
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
content = soup.find(u'table', {u'id': u'booklist'})
|
||||
content = content.findAll(u'tr')
|
||||
#log.debug(content)
|
||||
if not content:
|
||||
log.exception(u'No books found in the Biblegateway response.')
|
||||
send_error_message(u'parse')
|
||||
@ -171,7 +172,6 @@ class BGExtract(object):
|
||||
book = book.find(u'td')
|
||||
if book:
|
||||
books.append(book.contents[0])
|
||||
log.debug(book.contents[0])
|
||||
return books
|
||||
|
||||
|
||||
@ -180,7 +180,7 @@ class BSExtract(object):
|
||||
Extract verses from Bibleserver.com
|
||||
"""
|
||||
def __init__(self, proxyurl=None):
|
||||
log.debug(u'init %s', proxyurl)
|
||||
log.debug(u'BSExtract.init("%s")', proxyurl)
|
||||
self.proxyurl = proxyurl
|
||||
socket.setdefaulttimeout(30)
|
||||
|
||||
@ -197,9 +197,11 @@ class BSExtract(object):
|
||||
``chapter``
|
||||
Chapter number
|
||||
"""
|
||||
log.debug(u'get_bible_chapter %s,%s,%s', version, bookname, chapter)
|
||||
log.debug(u'BSExtract.get_bible_chapter("%s", "%s", "%s")', version,
|
||||
bookname, chapter)
|
||||
urlbookname = urllib.quote(bookname.encode("utf-8"))
|
||||
chapter_url = u'http://m.bibleserver.com/text/%s/%s%s' % \
|
||||
(version, bookname, chapter)
|
||||
(version, urlbookname, chapter)
|
||||
header = (u'Accept-Language', u'en')
|
||||
soup = get_soup_for_bible_ref(chapter_url, header)
|
||||
if not soup:
|
||||
@ -227,7 +229,7 @@ class BSExtract(object):
|
||||
``version``
|
||||
The version of the bible like NIV for New International Version
|
||||
"""
|
||||
log.debug(u'get_books_from_http %s', version)
|
||||
log.debug(u'BSExtract.get_books_from_http("%s")', version)
|
||||
chapter_url = u'http://m.bibleserver.com/overlay/selectBook?'\
|
||||
'translation=%s' % (version)
|
||||
soup = get_soup_for_bible_ref(chapter_url)
|
||||
@ -250,7 +252,7 @@ class CWExtract(object):
|
||||
Extract verses from CrossWalk/BibleStudyTools
|
||||
"""
|
||||
def __init__(self, proxyurl=None):
|
||||
log.debug(u'init %s', proxyurl)
|
||||
log.debug(u'CWExtract.init("%s")', proxyurl)
|
||||
self.proxyurl = proxyurl
|
||||
socket.setdefaulttimeout(30)
|
||||
|
||||
@ -267,10 +269,13 @@ class CWExtract(object):
|
||||
``chapter``
|
||||
Chapter number
|
||||
"""
|
||||
log.debug(u'get_bible_chapter %s,%s,%s', version, bookname, chapter)
|
||||
log.debug(u'CWExtract.get_bible_chapter("%s", "%s", "%s")', version,
|
||||
bookname, chapter)
|
||||
urlbookname = bookname.replace(u' ', u'-')
|
||||
urlbookname = urlbookname.lower()
|
||||
urlbookname = urllib.quote(urlbookname.encode("utf-8"))
|
||||
chapter_url = u'http://www.biblestudytools.com/%s/%s/%s.html' % \
|
||||
(version, urlbookname.lower(), chapter)
|
||||
(version, urlbookname, chapter)
|
||||
soup = get_soup_for_bible_ref(chapter_url)
|
||||
if not soup:
|
||||
return None
|
||||
@ -320,7 +325,7 @@ class CWExtract(object):
|
||||
``version``
|
||||
The version of the bible like NIV for New International Version
|
||||
"""
|
||||
log.debug(u'get_books_from_http %s', version)
|
||||
log.debug(u'CWExtract.get_books_from_http("%s")', version)
|
||||
chapter_url = u'http://www.biblestudytools.com/%s/'\
|
||||
% (version)
|
||||
soup = get_soup_for_bible_ref(chapter_url)
|
||||
@ -337,7 +342,6 @@ class CWExtract(object):
|
||||
for book in content:
|
||||
book = book.find(u'a')
|
||||
books.append(book.contents[0])
|
||||
log.debug(book.contents[0])
|
||||
return books
|
||||
|
||||
|
||||
@ -377,8 +381,10 @@ class HTTPBible(BibleDB):
|
||||
Run the import. This method overrides the parent class method. Returns
|
||||
``True`` on success, ``False`` on failure.
|
||||
"""
|
||||
self.wizard.progressBar.setMaximum(2)
|
||||
self.wizard.incrementProgressBar('Registering bible...')
|
||||
self.wizard.progressBar.setMaximum(68)
|
||||
self.wizard.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.HTTPBible',
|
||||
'Registering bible and loading books...')))
|
||||
self.create_meta(u'download source', self.download_source)
|
||||
self.create_meta(u'download name', self.download_name)
|
||||
if self.proxy_server:
|
||||
@ -400,6 +406,9 @@ class HTTPBible(BibleDB):
|
||||
log.exception(u'Importing books from %s - download name: "%s" '\
|
||||
'failed' % (self.download_source, self.download_name))
|
||||
return False
|
||||
self.wizard.progressBar.setMaximum(len(books)+2)
|
||||
self.wizard.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.HTTPBible', 'Registering Language...')))
|
||||
bible = BiblesResourcesDB.get_webbible(self.download_name,
|
||||
self.download_source.lower())
|
||||
if bible[u'language_id']:
|
||||
@ -415,6 +424,9 @@ class HTTPBible(BibleDB):
|
||||
# Store the language_id.
|
||||
self.create_meta(u'language_id', language_id)
|
||||
for book in books:
|
||||
self.wizard.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.HTTPBible', 'Importing %s...',
|
||||
'Importing <book name>...')) % book)
|
||||
book_ref_id = self.parent.manager.get_book_ref_id_by_name(book,
|
||||
language_id)
|
||||
if not book_ref_id:
|
||||
@ -427,7 +439,7 @@ class HTTPBible(BibleDB):
|
||||
self.create_book(book, book_ref_id, book_details[u'testament_id'])
|
||||
return True
|
||||
|
||||
def get_verses(self, reference_list, en_reference_list):
|
||||
def get_verses(self, reference_list):
|
||||
"""
|
||||
A reimplementation of the ``BibleDB.get_verses`` method, this one is
|
||||
specifically for web Bibles. It first checks to see if the particular
|
||||
@ -439,26 +451,19 @@ class HTTPBible(BibleDB):
|
||||
This is the list of references the media manager item wants. It is
|
||||
a list of tuples, with the following format::
|
||||
|
||||
(book, chapter, start_verse, end_verse)
|
||||
|
||||
``en_reference_list``
|
||||
This is the list of references the media manager item wants. It is
|
||||
a list of tuples, with the following format with englisch book
|
||||
names::
|
||||
|
||||
(book, chapter, start_verse, end_verse)
|
||||
(book_reference_id, chapter, start_verse, end_verse)
|
||||
|
||||
Therefore, when you are looking for multiple items, simply break
|
||||
them up into references like this, bundle them into a list. This
|
||||
function then runs through the list, and returns an amalgamated
|
||||
list of ``Verse`` objects. For example::
|
||||
|
||||
[(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)]
|
||||
[(u'35', 1, 1, 1), (u'35', 2, 2, 3)]
|
||||
"""
|
||||
log.debug(u'HTTPBible.get_verses("%s")', reference_list)
|
||||
for reference in reference_list:
|
||||
log.debug(u'Reference: %s', reference)
|
||||
book = reference[0]
|
||||
db_book = self.get_book(book)
|
||||
book_id = reference[0]
|
||||
db_book = self.get_book_by_book_ref_id(book_id)
|
||||
if not db_book:
|
||||
critical_error_message_box(
|
||||
translate('BiblesPlugin', 'No Book Found'),
|
||||
@ -467,7 +472,7 @@ class HTTPBible(BibleDB):
|
||||
'have spelled the name of the book correctly.'))
|
||||
return []
|
||||
book = db_book.name
|
||||
if BibleDB.get_verse_count(self, book, reference[1]) == 0:
|
||||
if BibleDB.get_verse_count(self, book_id, reference[1]) == 0:
|
||||
Receiver.send_message(u'cursor_busy')
|
||||
search_results = self.get_chapter(book, reference[1])
|
||||
if search_results and search_results.has_verselist():
|
||||
@ -484,13 +489,13 @@ class HTTPBible(BibleDB):
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
return BibleDB.get_verses(self, reference_list, en_reference_list)
|
||||
return BibleDB.get_verses(self, reference_list)
|
||||
|
||||
def get_chapter(self, book, chapter):
|
||||
"""
|
||||
Receive the request and call the relevant handler methods.
|
||||
"""
|
||||
log.debug(u'get_chapter %s, %s', book, chapter)
|
||||
log.debug(u'HTTPBible.get_chapter("%s", "%s")', book, chapter)
|
||||
log.debug(u'source = %s', self.download_source)
|
||||
if self.download_source.lower() == u'crosswalk':
|
||||
handler = CWExtract(self.proxy_server)
|
||||
@ -504,15 +509,17 @@ class HTTPBible(BibleDB):
|
||||
"""
|
||||
Return the list of books.
|
||||
"""
|
||||
log.debug(u'HTTPBible.get_books("%s")', Book.name)
|
||||
return self.get_all_objects(Book, order_by_ref=Book.id)
|
||||
|
||||
def get_chapter_count(self, book):
|
||||
def get_chapter_count(self, book_id):
|
||||
"""
|
||||
Return the number of chapters in a particular book.
|
||||
"""
|
||||
return BiblesResourcesDB.get_chapter_count(book)
|
||||
log.debug(u'HTTPBible.get_chapter_count("%s")', book_id)
|
||||
return BiblesResourcesDB.get_chapter_count(book_id)
|
||||
|
||||
def get_verse_count(self, book, chapter):
|
||||
def get_verse_count(self, book_id, chapter):
|
||||
"""
|
||||
Return the number of verses for the specified chapter and book.
|
||||
|
||||
@ -522,7 +529,8 @@ class HTTPBible(BibleDB):
|
||||
``chapter``
|
||||
The chapter whose verses are being counted.
|
||||
"""
|
||||
return BiblesResourcesDB.get_verse_count(book, chapter)
|
||||
log.debug(u'HTTPBible.get_verse_count("%s", %s)', book_id, chapter)
|
||||
return BiblesResourcesDB.get_verse_count(book_id, chapter)
|
||||
|
||||
def get_soup_for_bible_ref(reference_url, header=None, pre_parse_regex=None,
|
||||
pre_parse_substitute=None, cleaner=None):
|
||||
|
@ -30,10 +30,11 @@ import os
|
||||
from PyQt4 import QtCore
|
||||
|
||||
from openlp.core.lib import Receiver, SettingsManager, translate
|
||||
from openlp.core.lib.ui import critical_error_message_box
|
||||
from openlp.core.utils import AppLocation, delete_file
|
||||
from openlp.plugins.bibles.lib import parse_reference
|
||||
from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta, SpellingDB, \
|
||||
Spelling, BiblesResourcesDB
|
||||
BiblesResourcesDB
|
||||
from csvbible import CSVBible
|
||||
from http import HTTPBible
|
||||
from opensong import OpenSongBible
|
||||
@ -223,14 +224,10 @@ class BibleManager(object):
|
||||
language_id = self.get_meta_data(bible, u'language_id')
|
||||
books = []
|
||||
for book in self.db_cache[bible].get_books():
|
||||
book_id = self.get_book_ref_id_by_name(book.name, int(
|
||||
language_id.value))
|
||||
book_temp = BiblesResourcesDB.get_book_by_id(book_id)
|
||||
book_ref = book_temp[u'name']
|
||||
books.append(
|
||||
{
|
||||
u'name': book.name,
|
||||
u'chapters': self.db_cache[bible].get_chapter_count(book_ref)
|
||||
u'chapters': self.db_cache[bible].get_chapter_count(book.book_reference_id)
|
||||
})
|
||||
return books
|
||||
|
||||
@ -240,8 +237,6 @@ class BibleManager(object):
|
||||
"""
|
||||
log.debug(u'BibleManager.get_book_chapter_count ("%s", "%s")', bible,
|
||||
book)
|
||||
language_id = self.get_meta_data(bible, u'language_id')
|
||||
book = self.get_book_ref(book, int(language_id.value))
|
||||
return self.db_cache[bible].get_chapter_count(book)
|
||||
|
||||
def get_verse_count(self, bible, book, chapter):
|
||||
@ -251,11 +246,11 @@ class BibleManager(object):
|
||||
"""
|
||||
log.debug(u'BibleManager.get_verse_count("%s", "%s", %s)',
|
||||
bible, book, chapter)
|
||||
language_id = self.get_meta_data(bible, u'language_id')
|
||||
book = self.get_book_ref(book, int(language_id.value))
|
||||
return self.db_cache[bible].get_verse_count(book, chapter)
|
||||
db_book = self.db_cache[bible].get_book(book)
|
||||
book_ref_id = db_book.book_reference_id
|
||||
return self.db_cache[bible].get_verse_count(book_ref_id, chapter)
|
||||
|
||||
def get_verses(self, bible, versetext, secondbible=False):
|
||||
def get_verses(self, bible, versetext, firstbible=False):
|
||||
"""
|
||||
Parses a scripture reference, fetches the verses from the Bible
|
||||
specified, and returns a list of ``Verse`` objects.
|
||||
@ -286,31 +281,29 @@ class BibleManager(object):
|
||||
return None
|
||||
reflist = parse_reference(versetext)
|
||||
if reflist:
|
||||
# if we use a second bible we have to rename the book names
|
||||
if secondbible:
|
||||
log.debug(u'BibleManager.get_verses("secondbible true")')
|
||||
meta = self.db_cache[bible].get_object(BibleMeta,
|
||||
u'language_id')
|
||||
language_id = meta.value
|
||||
new_reflist = []
|
||||
for item in reflist:
|
||||
if item:
|
||||
book = self.get_book_ref(item[0])
|
||||
book_ref_id = self.parent.manager.\
|
||||
get_book_ref_id_by_name(book, language_id)
|
||||
book = self.db_cache[bible].get_book_by_book_ref_id(
|
||||
book_ref_id)
|
||||
new_reflist.append((book.name, item[1], item[2],
|
||||
if firstbible:
|
||||
db_book = self.db_cache[firstbible].get_book(item[0])
|
||||
db_book = self.db_cache[bible].get_book_by_book_ref_id(
|
||||
db_book.book_reference_id)
|
||||
else:
|
||||
db_book = self.db_cache[bible].get_book(item[0])
|
||||
if db_book:
|
||||
book_id = db_book.book_reference_id
|
||||
log.debug(u'Book name corrected to "%s"', db_book.name)
|
||||
new_reflist.append((book_id, item[1], item[2],
|
||||
item[3]))
|
||||
else:
|
||||
log.debug(u'OpenLP failed to find book %s', item[0])
|
||||
critical_error_message_box(
|
||||
translate('BiblesPlugin', 'No Book Found'),
|
||||
translate('BiblesPlugin', 'No matching book '
|
||||
'could be found in this Bible. Check that you have '
|
||||
'spelled the name of the book correctly.'))
|
||||
reflist = new_reflist
|
||||
log.debug(u'BibleManager.get_verses("reflist: %s")', reflist)
|
||||
en_reflist = []
|
||||
for item in reflist:
|
||||
if item:
|
||||
book = self.get_book_ref(item[0])
|
||||
en_reflist.append((book, item[1], item[2], item[3]))
|
||||
log.debug(u'BibleManager.get_verses("en_reflist: %s")', en_reflist)
|
||||
return self.db_cache[bible].get_verses(reflist, en_reflist)
|
||||
return self.db_cache[bible].get_verses(reflist)
|
||||
else:
|
||||
Receiver.send_message(u'openlp_information_message', {
|
||||
u'title': translate('BiblesPlugin.BibleManager',
|
||||
@ -332,7 +325,8 @@ class BibleManager(object):
|
||||
log.debug(u'BibleManager.get_book_ref("%s", "%s")', book, language_id)
|
||||
book_id = self.get_book_ref_id_by_name(book, language_id)
|
||||
book_temp = BiblesResourcesDB.get_book_by_id(book_id)
|
||||
log.debug(u'get_book_ref - Return:%s', book_temp[u'name'])
|
||||
log.debug(u'BibleManager.get_book_ref("Return: %s")',
|
||||
book_temp[u'name'])
|
||||
return book_temp[u'name']
|
||||
|
||||
def get_book_ref_id_by_name(self, book, language_id=None):
|
||||
@ -360,7 +354,6 @@ class BibleManager(object):
|
||||
self.spelling_cache[u'spelling'].create_spelling(book, book_id,
|
||||
language_id)
|
||||
if book_id:
|
||||
log.debug(u'get_book_ref_id_by_name - Return:%s', book_id)
|
||||
return book_id
|
||||
else:
|
||||
return None
|
||||
|
@ -482,7 +482,7 @@ class BibleMediaItem(MediaManagerItem):
|
||||
self.search_results = self.parent.manager.get_verses(bible, versetext)
|
||||
if second_bible:
|
||||
self.second_search_results = self.parent.manager.get_verses(
|
||||
second_bible, versetext, True)
|
||||
second_bible, versetext, bible)
|
||||
if self.advancedClearComboBox.currentIndex() == 0:
|
||||
self.listView.clear()
|
||||
if self.listView.count() != 0:
|
||||
@ -509,7 +509,7 @@ class BibleMediaItem(MediaManagerItem):
|
||||
self.search_results = self.parent.manager.get_verses(bible, text)
|
||||
if second_bible and self.search_results:
|
||||
self.second_search_results = self.parent.manager.get_verses(
|
||||
second_bible, text, True)
|
||||
second_bible, text, bible)
|
||||
else:
|
||||
# We are doing a 'Text Search'.
|
||||
Receiver.send_message(u'cursor_busy')
|
||||
|
@ -85,7 +85,8 @@ class OpenLP1Bible(BibleDB):
|
||||
'failed' % self.filename)
|
||||
return False
|
||||
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
|
||||
self.create_book(name, book_ref_id, book_details[u'testament_id'])
|
||||
db_book = self.create_book(name, book_ref_id,
|
||||
book_details[u'testament_id'])
|
||||
# Update the progess bar.
|
||||
self.wizard.incrementProgressBar(WizardStrings.ImportingType % name)
|
||||
# Import the verses for this book.
|
||||
@ -99,7 +100,7 @@ class OpenLP1Bible(BibleDB):
|
||||
chapter = int(verse[0])
|
||||
verse_number = int(verse[1])
|
||||
text = unicode(verse[2], u'cp1252')
|
||||
self.create_verse(book_id, chapter, verse_number, text)
|
||||
self.create_verse(db_book.id, chapter, verse_number, text)
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
self.session.commit()
|
||||
connection.close()
|
||||
|
@ -92,7 +92,8 @@ class OSISBible(BibleDB):
|
||||
osis = None
|
||||
success = True
|
||||
last_chapter = 0
|
||||
testament = 1
|
||||
#TODO: Delete unused code
|
||||
#testament = 1
|
||||
match_count = 0
|
||||
self.wizard.incrementProgressBar(translate('BiblesPlugin.OsisImport',
|
||||
'Detecting encoding (this may take a few minutes)...'))
|
||||
@ -128,15 +129,18 @@ class OSISBible(BibleDB):
|
||||
verse_text = match.group(4)
|
||||
if not db_book or db_book.name != self.books[book][0]:
|
||||
log.debug(u'New book: "%s"', self.books[book][0])
|
||||
if book == u'Matt' or book == u'Jdt':
|
||||
testament += 1
|
||||
book_ref_id = self.parent.manager.get_book_ref_id_by_name(
|
||||
#TODO: Delete unused code
|
||||
#if book == u'Matt' or book == u'Jdt':
|
||||
# testament += 1
|
||||
book_ref_id = self.parent.manager.\
|
||||
get_book_ref_id_by_name(
|
||||
unicode(self.books[book][0]), language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from %s " '\
|
||||
'failed' % self.filename)
|
||||
return False
|
||||
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
|
||||
book_details = BiblesResourcesDB.get_book_by_id(
|
||||
book_ref_id)
|
||||
db_book = self.create_book(
|
||||
unicode(self.books[book][0]),
|
||||
book_ref_id,
|
||||
|
Loading…
Reference in New Issue
Block a user