diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index ac80434ca..94d8e6567 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -329,8 +329,8 @@ class BibleImportForm(OpenLPWizard): self.open_song_file_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible file:')) self.web_source_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Location:')) self.zefania_file_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible file:')) - self.web_update_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Click to fetch bible list')) - self.web_update_button.setText(translate('BiblesPlugin.ImportWizardForm', 'Fetch list')) + self.web_update_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Click to download bible list')) + self.web_update_button.setText(translate('BiblesPlugin.ImportWizardForm', 'Download bible list')) self.web_source_combo_box.setItemText(WebDownload.Crosswalk, translate('BiblesPlugin.ImportWizardForm', 'Crosswalk')) self.web_source_combo_box.setItemText(WebDownload.BibleGateway, translate('BiblesPlugin.ImportWizardForm', @@ -504,6 +504,7 @@ class BibleImportForm(OpenLPWizard): self.web_bible_list = {} self.web_source_combo_box.setEnabled(False) self.web_translation_combo_box.setEnabled(False) + self.web_update_button.setEnabled(False) self.web_progress_bar.setVisible(True) self.web_progress_bar.setValue(0) proxy_server = self.field('proxy_server') @@ -518,13 +519,14 @@ class BibleImportForm(OpenLPWizard): 'An error occurred while downloading the list of bibles from %s.')) self.web_bible_list[download_type] = {} for (bible_name, bible_key, language_code) in bibles: - self.web_bible_list[download_type][bible_name] = bible_key + self.web_bible_list[download_type][bible_name] = (bible_key, language_code) self.web_progress_bar.setValue(download_type + 1) # Update combo box if something got into the list if self.web_bible_list: self.on_web_source_combo_box_index_changed(0) self.web_source_combo_box.setEnabled(True) self.web_translation_combo_box.setEnabled(True) + self.web_update_button.setEnabled(True) self.web_progress_bar.setVisible(False) def register_fields(self): @@ -611,14 +613,15 @@ class BibleImportForm(OpenLPWizard): self.progress_bar.setMaximum(1) download_location = self.field('web_location') bible_version = self.web_translation_combo_box.currentText() - bible = self.web_bible_list[download_location][bible_version] + (bible, language_id) = self.web_bible_list[download_location][bible_version] importer = self.manager.import_bible( BibleFormat.WebDownload, name=license_version, download_source=WebDownload.Names[download_location], download_name=bible, proxy_server=self.field('proxy_server'), proxy_username=self.field('proxy_username'), - proxy_password=self.field('proxy_password') + proxy_password=self.field('proxy_password'), + language_id=language_id ) elif bible_type == BibleFormat.Zefania: # Import an Zefania bible. diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 858afdd63..5c8443f23 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -791,13 +791,12 @@ class BiblesResourcesDB(QtCore.QObject, Manager): if not isinstance(name, str): name = str(name) language = BiblesResourcesDB.run_sql( - 'SELECT id, name, code, native_name FROM language WHERE name = ? OR code = ?', (name, name.lower())) + 'SELECT id, name, code FROM language WHERE name = ? OR code = ?', (name, name.lower())) if language: return { 'id': language[0][0], 'name': str(language[0][1]), - 'code': str(language[0][2]), - 'native_name': str(language[0][3]) + 'code': str(language[0][2]) } else: return None diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 6b1d96b4e..e2df05c90 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -254,6 +254,8 @@ class BGExtract(RegistryProperties): if not soup: return None div = soup.find('div', 'result-text-style-normal') + if not div: + return None self._clean_soup(div) span_list = div.find_all('span', 'text') log.debug('Span list: %s', span_list) @@ -322,7 +324,13 @@ class BGExtract(RegistryProperties): if not soup: return None bible_select = soup.find('select', {'class': 'translation-dropdown'}) + if not bible_select: + log.debug('No select tags found - did site change?') + return None option_tags = bible_select.find_all('option') + if not option_tags: + log.debug('No option tags found - did site change?') + return None current_lang = '' bibles = [] for ot in option_tags: @@ -412,15 +420,21 @@ class BSExtract(RegistryProperties): if not soup: return None bible_links = soup.find_all('a', {'class': 'trlCell'}) + if not bible_links: + log.debug('No a tags found - did site change?') + return None bibles = [] for link in bible_links: bible_name = link.get_text() # Skip any audio if 'audio' in bible_name.lower(): continue - bible_link = link['href'] - bible_key = bible_link[bible_link.rfind('/') + 1:] - css_classes = link['class'] + try: + bible_link = link['href'] + bible_key = bible_link[bible_link.rfind('/') + 1:] + css_classes = link['class'] + except KeyError: + log.debug('No href/class attribute found - did site change?') language_code = '' for css_class in css_classes: if css_class.startswith('fl_'): @@ -512,11 +526,21 @@ class CWExtract(RegistryProperties): if not soup: return None bible_select = soup.find('select') + if not bible_select: + log.debug('No select tags found - did site change?') + return None option_tags = bible_select.find_all('option') + if not option_tags: + log.debug('No option tags found - did site change?') + return None bibles = [] for ot in option_tags: tag_text = ot.get_text().strip() - tag_value = ot['value'] + try: + tag_value = ot['value'] + except KeyError: + log.exception('No value attribute found - did site change?') + return None if not tag_value: continue # The names of non-english bibles has their language in parentheses at the end @@ -524,7 +548,6 @@ class CWExtract(RegistryProperties): language = tag_text[tag_text.rfind('(') + 1:-1] if language in CROSSWALK_LANGUAGES: language_code = CROSSWALK_LANGUAGES[language] - tag_text = tag_text[:tag_text.rfind('(')] else: language_code = '' # ... except for the latin vulgate @@ -555,6 +578,7 @@ class HTTPBible(BibleDB, RegistryProperties): self.proxy_server = None self.proxy_username = None self.proxy_password = None + self.language_id = None if 'path' in kwargs: self.path = kwargs['path'] if 'proxy_server' in kwargs: @@ -563,6 +587,8 @@ class HTTPBible(BibleDB, RegistryProperties): self.proxy_username = kwargs['proxy_username'] if 'proxy_password' in kwargs: self.proxy_password = kwargs['proxy_password'] + if 'language_id' in kwargs: + self.language_id = kwargs['language_id'] def do_import(self, bible_name=None): """ @@ -595,13 +621,12 @@ class HTTPBible(BibleDB, RegistryProperties): return False self.wizard.progress_bar.setMaximum(len(books) + 2) self.wizard.increment_progress_bar(translate('BiblesPlugin.HTTPBible', 'Registering Language...')) - bible = BiblesResourcesDB.get_webbible(self.download_name, self.download_source.lower()) - if bible['language_id']: - language_id = bible['language_id'] - self.save_meta('language_id', language_id) + bible = None #BiblesResourcesDB.get_webbible(self.download_name, self.download_source.lower()) + if self.language_id: + self.save_meta('language_id', self.language_id) else: - language_id = self.get_language(bible_name) - if not language_id: + self.language_id = self.get_language(bible_name) + if not self.language_id: log.error('Importing books from %s failed' % self.filename) return False for book in books: @@ -609,7 +634,7 @@ class HTTPBible(BibleDB, RegistryProperties): break self.wizard.increment_progress_bar(translate( 'BiblesPlugin.HTTPBible', 'Importing %s...', 'Importing ...') % book) - book_ref_id = self.get_book_ref_id_by_name(book, len(books), language_id) + book_ref_id = self.get_book_ref_id_by_name(book, len(books), self.language_id) if not book_ref_id: log.error('Importing books from %s - download name: "%s" failed' % (self.download_source, self.download_name)) diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_http.py b/tests/interfaces/openlp_plugins/bibles/test_lib_http.py index c422f6e5f..ff9ce0382 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_http.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_http.py @@ -124,8 +124,13 @@ class TestBibleHTTP(TestCase): # GIVEN: A new Bible Server extraction class handler = BSExtract() - handler.get_bibles_from_http() - self.assertTrue(False) + # WHEN: downloading bible list from bibleserver + bibles = handler.get_bibles_from_http() + + # THEN: The list should not be None, and some known bibles should be there + self.assertIsNotNone(bibles) + self.assertIn(('New Int. Readers Version', 'NIRV', 'en'), bibles) + self.assertIn(('Българската Библия', 'BLG', 'bg'), bibles) def biblegateway_get_bibles_test(self): """ @@ -134,8 +139,12 @@ class TestBibleHTTP(TestCase): # GIVEN: A new Bible Gateway extraction class handler = BGExtract() - handler.get_bibles_from_http() - self.assertTrue(False) + # WHEN: downloading bible list from Crosswalk + bibles = handler.get_bibles_from_http() + + # THEN: The list should not be None, and some known bibles should be there + self.assertIsNotNone(bibles) + self.assertIn(('Holman Christian Standard Bible', 'HCSB', 'en'), bibles) def crosswalk_get_bibles_test(self): """ @@ -144,5 +153,9 @@ class TestBibleHTTP(TestCase): # GIVEN: A new Crosswalk extraction class handler = CWExtract() - handler.get_bibles_from_http() - self.assertTrue(False) + # WHEN: downloading bible list from Crosswalk + bibles = handler.get_bibles_from_http() + + # THEN: The list should not be None, and some known bibles should be there + self.assertIsNotNone(bibles) + self.assertIn(('Giovanni Diodati 1649 (Italian)', 'gdb', 'it'), bibles)