From 428edf28fb5abf3fea66b13aab61764fb7acc101 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sun, 30 Jan 2011 09:32:09 +0000 Subject: [PATCH 1/5] CSV testing named book format (v1?) --- openlp/plugins/bibles/lib/csvbible.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index fd987dfdf..33a5de714 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -172,8 +172,12 @@ class CSVBible(BibleDB): for line in verse_reader: if self.stop_import_flag: break - if book_ptr != book_list[int(line[0])]: - book = self.get_book(book_list[int(line[0])]) + try: + line_book = book_list[int(line[0])] + except ValueError: + line_book = unicode(line[0], details['encoding']) + if book_ptr != line_book: + book = self.get_book(line_book) book_ptr = book.name self.wizard.incrementProgressBar(unicode(translate( 'BibleDB.Wizard', 'Importing verses from %s...', From 780a8b8b39727c8daea1a418a79c6d71d82971e8 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sun, 30 Jan 2011 09:43:07 +0000 Subject: [PATCH 2/5] Docstring update for CSV formats --- openlp/plugins/bibles/lib/csvbible.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index 33a5de714..677f99e6b 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -50,14 +50,17 @@ The format of the books file is: ... 40,2,Matthew,Matt -The format of the verses file is: +There are two acceptable formats of the verses file. They are: ,,, + or + ,,, For example: 1,1,1,"In the beginning God created the heaven and the earth." - 1,1,2,"And the earth was without form, and void; and darkness...." + or + "Genesis",1,2,"And the earth was without form, and void; and...." All CSV files are expected to use a comma (',') as the delimeter and double quotes ('"') as the quote symbol. From 54a6963f892a9c66c04fa396620f6f375fafad04 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 30 Jan 2011 21:08:00 +0100 Subject: [PATCH 3/5] changed image title --- openlp/plugins/images/lib/mediaitem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 73f5b80f0..25d9811f1 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -142,7 +142,7 @@ class ImageMediaItem(MediaManagerItem): items = self.listView.selectedIndexes() if items: service_item.title = unicode( - translate('ImagePlugin.MediaItem', 'Image(s)')) + translate('ImagePlugin.MediaItem', 'Images')) service_item.add_capability(ItemCapabilities.AllowsMaintain) service_item.add_capability(ItemCapabilities.AllowsPreview) service_item.add_capability(ItemCapabilities.AllowsLoop) From b99961d669c9f71ac6d33a3d7e4411f4ad7444af Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Mon, 31 Jan 2011 01:55:25 +0000 Subject: [PATCH 4/5] Fix BG Chinese bible (Bug #706211) --- openlp/plugins/bibles/lib/http.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index b844bbe61..e004be9df 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -210,7 +210,8 @@ class BGExtract(object): cleaner = [(re.compile(' |
|\'\+\''), lambda match: '')] soup = get_soup_for_bible_ref( u'http://www.biblegateway.com/passage/?%s' % url_params, - cleaner=cleaner) + pre_parse_regex=r'', pre_parse_substitute='', + cleaner=cleaner) if not soup: return None Receiver.send_message(u'openlp_process_events') @@ -499,7 +500,8 @@ class HTTPBible(BibleDB): """ return HTTPBooks.get_verse_count(book, chapter) -def get_soup_for_bible_ref(reference_url, header=None, cleaner=None): +def get_soup_for_bible_ref(reference_url, header=None, pre_parse_regex=None, + pre_parse_substitute=None, cleaner=None): """ Gets a webpage and returns a parsed and optionally cleaned soup or None. @@ -509,6 +511,13 @@ def get_soup_for_bible_ref(reference_url, header=None, cleaner=None): ``header`` An optional HTTP header to pass to the bible web server. + ``pre_parse_regex`` + A regular expression to run on the webpage. Allows manipulation of the + webpage before passing to BeautifulSoup for parsing. + + ``pre_parse_substitute`` + The text to replace any matches to the regular expression with. + ``cleaner`` An optional regex to use during webpage parsing. """ @@ -518,12 +527,15 @@ def get_soup_for_bible_ref(reference_url, header=None, cleaner=None): if not page: send_error_message(u'download') return None + 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) soup = None try: if cleaner: - soup = BeautifulSoup(page, markupMassage=cleaner) + soup = BeautifulSoup(page_source, markupMassage=cleaner) else: - soup = BeautifulSoup(page) + soup = BeautifulSoup(page_source) except HTMLParseError: log.exception(u'BeautifulSoup could not parse the bible page.') if not soup: From 250107073e86d399d1b792d9b2d3087e4dca72c4 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Mon, 31 Jan 2011 02:43:37 +0000 Subject: [PATCH 5/5] Fix not quite ascii CSVs --- openlp/plugins/bibles/lib/csvbible.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index 677f99e6b..82872e15b 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -186,8 +186,11 @@ class CSVBible(BibleDB): 'BibleDB.Wizard', 'Importing verses from %s...', 'Importing verses from ...')) % book.name) self.session.commit() - self.create_verse(book.id, line[1], line[2], - unicode(line[3], details['encoding'])) + try: + verse_text = unicode(line[3], details['encoding']) + except UnicodeError: + verse_text = unicode(line[3], u'cp1252') + self.create_verse(book.id, line[1], line[2], verse_text) self.wizard.incrementProgressBar(translate('BibleDB.Wizard', 'Importing verses... done.')) Receiver.send_message(u'openlp_process_events')