openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #06806
[Merge] lp:~orangeshirt/openlp/webbibles into lp:openlp
Armin Köhler has proposed merging lp:~orangeshirt/openlp/webbibles into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~orangeshirt/openlp/webbibles/+merge/52601
added download for all books a web bible contains while importing the web bible (works for Bibleserver and Crosswalk)
changed the behavior of selectable books in advanced search (only books which a bible contains are selectable or to precise that: only books both bibles (first and second choose) contains are selectable)
changed the behavior of AutoCompleter in QuickSearch - the AutoCompleter now only suggest bookname which are contained in both (first and second) bible versions if two versions are choosen, otherwise it suggest the books the first bible includes
--
https://code.launchpad.net/~orangeshirt/openlp/webbibles/+merge/52601
Your team OpenLP Core is requested to review the proposed merge of lp:~orangeshirt/openlp/webbibles into lp:openlp.
=== modified file 'openlp/plugins/bibles/lib/http.py'
--- openlp/plugins/bibles/lib/http.py 2011-02-26 00:36:07 +0000
+++ openlp/plugins/bibles/lib/http.py 2011-03-08 19:46:15 +0000
@@ -258,6 +258,44 @@
send_error_message(u'parse')
return None
return SearchResults(bookname, chapter, verse_list)
+
+ def get_books_from_http(self, version):
+ """
+ Access and decode bibles via BibleGateway website
+
+ ``version``
+ The version of the bible like NIV for New International Version
+ """
+ log.debug(u'get_books_from_http %s', version)
+ bookname = u'Luke'
+ chapter = u'1'
+ url_params = urllib.urlencode(
+ {u'search': u'%s %s' % (bookname, chapter),
+ u'version': u'%s' % version})
+ cleaner = [(re.compile(' |<br />|\'\+\''), lambda match: '')]
+ soup = get_soup_for_bible_ref(
+ u'http://www.biblegateway.com/passage/?%s' % url_params,
+ pre_parse_regex=r'<meta name.*?/>', pre_parse_substitute='',
+ cleaner=cleaner)
+ #TODO: Error while parsing soup
+ if not soup:
+ return None
+ content = soup.find(u'table', {u'id': u'booklist'})
+ log.debug(content)
+ 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')
+ return None
+ books = []
+ for book in content:
+ book = book.find(u'td')
+ if book:
+ books.append(book.contents[0])
+ log.debug(book.contents[0])
+ #TODO: translate book names to english or anything similar
+ return books
class BSExtract(object):
@@ -304,6 +342,35 @@
verses[versenumber] = verse.contents[1].rstrip(u'\n')
return SearchResults(bookname, chapter, verses)
+ def get_books_from_http(self, version):
+ """
+ Access and decode bibles via Bibleserver mobile website
+
+ ``version``
+ The version of the bible like NIV for New International Version
+ """
+ log.debug(u'get_books_from_http %s', version)
+ chapter_url = u'http://m.bibleserver.com/overlay/selectBook?'\
+ 'translation=%s&language=EN' % (version)
+ header = (u'Accept-Language', u'en')
+ soup = get_soup_for_bible_ref(chapter_url, header)
+ if not soup:
+ return None
+ content = soup.find(u'ul')
+ if not content:
+ log.exception(u'No books found in the Bibleserver response.')
+ send_error_message(u'parse')
+ return None
+ content = content.findAll(u'li')
+ books = []
+ for book in content:
+ if book.contents[0].contents[0] == u'Numeri':
+ book.contents[0].contents[0] = u'Numbers'
+ elif book.contents[0].contents[0] == u'Habbakuk':
+ book.contents[0].contents[0] = u'Habakkuk'
+ books.append(book.contents[0].contents[0])
+ return books
+
class CWExtract(object):
"""
@@ -372,6 +439,33 @@
versetext = fix_punctuation.sub(r'\1', versetext)
verses[versenumber] = versetext
return SearchResults(bookname, chapter, verses)
+
+ def get_books_from_http(self, version):
+ """
+ Access and decode bibles via Crosswalk website
+
+ ``version``
+ The version of the bible like NIV for New International Version
+ """
+ log.debug(u'get_books_from_http %s', version)
+ chapter_url = u'http://www.biblestudytools.com/%s/'\
+ % (version)
+ soup = get_soup_for_bible_ref(chapter_url)
+ if not soup:
+ return None
+ content = soup.find(u'div', {u'class': u'Body'})
+ content = content.find(u'ul', {u'class': u'parent'})
+ if not content:
+ log.exception(u'No books found in the Crosswalk response.')
+ send_error_message(u'parse')
+ return None
+ content = content.findAll(u'li')
+ books = []
+ for book in content:
+ book = book.find(u'a')
+ books.append(book.contents[0])
+ log.debug(book.contents[0])
+ return books
class HTTPBible(BibleDB):
@@ -419,6 +513,25 @@
if self.proxy_password:
# Store the proxy password.
self.create_meta(u'proxy password', self.proxy_password)
+ if self.download_source.lower() == u'crosswalk':
+ handler = CWExtract(self.proxy_server)
+ elif self.download_source.lower() == u'biblegateway':
+ handler = BGExtract(self.proxy_server)
+ elif self.download_source.lower() == u'bibleserver':
+ handler = BSExtract(self.proxy_server)
+ books = handler.get_books_from_http(self.download_name)
+ if not books:
+ log.exception(u'Importing books from %s - download name: "%s" '\
+ 'failed' % (self.download_source, self.download_name))
+ return False
+ for book in books:
+ book_details = HTTPBooks.get_book(book)
+ log.debug(u'Book details: %s; %s; %s', book_details[u'name'],
+ book_details[u'abbreviation'],
+ book_details[u'testament_id'])
+ self.create_book(book_details[u'name'],
+ book_details[u'abbreviation'],
+ book_details[u'testament_id'])
return True
def get_verses(self, reference_list):
@@ -496,8 +609,9 @@
"""
Return the list of books.
"""
- return [Book.populate(name=book['name'])
- for book in HTTPBooks.get_books()]
+ return self.get_all_objects(Book, order_by_ref=Book.id)
+ #return [Book.populate(name=book['name'])
+ # for book in HTTPBooks.get_books()]
def get_chapter_count(self, book):
"""
@@ -547,6 +661,7 @@
page_source = page.read()
if pre_parse_regex and pre_parse_substitute is not None:
page_source = re.sub(pre_parse_regex, pre_parse_substitute, page_source)
+ log.debug(page)
soup = None
try:
if cleaner:
=== modified file 'openlp/plugins/bibles/lib/mediaitem.py'
--- openlp/plugins/bibles/lib/mediaitem.py 2011-03-05 12:03:37 +0000
+++ openlp/plugins/bibles/lib/mediaitem.py 2011-03-08 19:46:15 +0000
@@ -196,8 +196,14 @@
# Add the search tab widget to the page layout.
self.pageLayout.addWidget(self.searchTabWidget)
# Combo Boxes
+ QtCore.QObject.connect(self.quickVersionComboBox,
+ QtCore.SIGNAL(u'activated(int)'), self.onQuickVersionComboBox)
+ QtCore.QObject.connect(self.quickSecondComboBox,
+ QtCore.SIGNAL(u'activated(int)'), self.onQuickSecondComboBox)
QtCore.QObject.connect(self.advancedVersionComboBox,
QtCore.SIGNAL(u'activated(int)'), self.onAdvancedVersionComboBox)
+ QtCore.QObject.connect(self.advancedSecondComboBox,
+ QtCore.SIGNAL(u'activated(int)'), self.onAdvancedSecondComboBox)
QtCore.QObject.connect(self.advancedBookComboBox,
QtCore.SIGNAL(u'activated(int)'), self.onAdvancedBookComboBox)
QtCore.QObject.connect(self.advancedFromChapter,
@@ -314,7 +320,7 @@
self.parent.manager.reload_bibles()
self.loadBibles()
- def initialiseBible(self, bible):
+ def initialiseBible(self, bible, second_bible=None):
"""
This initialises the given bible, which means that its book names and
their chapter numbers is added to the combo boxes on the
@@ -325,7 +331,15 @@
The bible to initialise (unicode).
"""
log.debug(u'initialiseBible %s', bible)
- book_data = self.parent.manager.get_books(bible)
+ first_book_data = self.parent.manager.get_books(bible)
+ if second_bible:
+ second_book_data = self.parent.manager.get_books(second_bible)
+ if len(first_book_data) <= len(second_book_data):
+ book_data = first_book_data
+ if len(first_book_data) > len(second_book_data):
+ book_data = second_book_data
+ else:
+ book_data = first_book_data
self.advancedBookComboBox.clear()
first = True
for book in book_data:
@@ -364,16 +378,39 @@
# We have to do a 'Reference Search'.
if self.quickSearchEdit.currentSearchType() == BibleSearch.Reference:
bibles = self.parent.manager.get_bibles()
- bible = unicode(self.quickVersionComboBox.currentText())
- if bible:
- book_data = bibles[bible].get_books()
+ first_bible = unicode(self.quickVersionComboBox.currentText())
+ second_bible = unicode(self.quickSecondComboBox.currentText())
+ if first_bible:
+ first_book_data = bibles[first_bible].get_books()
+ if second_bible:
+ second_book_data = bibles[second_bible].get_books()
+ if len(first_book_data) <= len(second_book_data):
+ book_data = first_book_data
+ if len(first_book_data) > len(second_book_data):
+ book_data = second_book_data
+ else:
+ book_data = bibles[first_bible].get_books()
books = [book.name for book in book_data]
books.sort()
add_widget_completer(books, self.quickSearchEdit)
+ def onQuickVersionComboBox(self):
+ self.updateAutoCompleter()
+
+ def onQuickSecondComboBox(self):
+ self.updateAutoCompleter()
+ #TODO: Change
+
def onAdvancedVersionComboBox(self):
self.initialiseBible(
- unicode(self.advancedVersionComboBox.currentText()))
+ unicode(self.advancedVersionComboBox.currentText()),
+ unicode(self.advancedSecondComboBox.currentText()))
+
+ def onAdvancedSecondComboBox(self):
+ self.initialiseBible(
+ unicode(self.advancedVersionComboBox.currentText()),
+ unicode(self.advancedSecondComboBox.currentText()))
+ #TODO: read the other Bible Version
def onAdvancedBookComboBox(self):
item = int(self.advancedBookComboBox.currentIndex())