Merge lp:~raoul-snyman/openlp/biblefixes into lp:openlp

Proposed by Raoul Snyman
Status: Merged
Merged at revision: not available
Proposed branch: lp:~raoul-snyman/openlp/biblefixes
Merge into: lp:openlp
Diff against target: None lines
To merge this branch: bzr merge lp:~raoul-snyman/openlp/biblefixes
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Review via email: mp+8345@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Fixes issues that some of us were having.

Revision history for this message
Tim Bentley (trb143) wrote :

Nice one. Looks much better now!

review: Approve
lp:~raoul-snyman/openlp/biblefixes updated
483. By Tim Bentley

Remove unused stuff
Add more bits to ImageSlideController bar
Clean up ThemeManager
Add OOS saving

484. By Raoul Snyman

Fixed up a few logging things, a few bits of indentation, and resolved some conflicts from the last update.

485. By Raoul Snyman

Merged changes to Bible plugin into trunk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/plugins/bibles/lib/common.py'
--- openlp/plugins/bibles/lib/common.py 2009-06-20 19:11:17 +0000
+++ openlp/plugins/bibles/lib/common.py 2009-07-07 20:18:36 +0000
@@ -19,93 +19,140 @@
19import os.path19import os.path
20import sys20import sys
21import urllib221import urllib2
2222import chardet
23import logging23import logging
2424
25class SearchResults:25class SearchResults:
26 """
27 Encapsulate a set of search results. This is Bible-type independant.
28 """
26 def __init__(self, book, chapter, verselist):29 def __init__(self, book, chapter, verselist):
30 """
31 Create the search result object.
32
33 ``book``
34 The book of the Bible.
35
36 ``chapter``
37 The chapter of the book.
38
39 ``verselist``
40 The list of verses for this reading
41 """
27 self.book = book42 self.book = book
28 self.chapter = chapter43 self.chapter = chapter
29 self.verselist = verselist44 self.verselist = verselist
45
30 def get_verselist(self):46 def get_verselist(self):
47 """
48 Returns the list of verses.
49 """
31 return self.verselist50 return self.verselist
51
32 def get_book(self):52 def get_book(self):
53 """
54 Returns the book of the Bible.
55 """
33 return self.book56 return self.book
57
34 def get_chapter(self):58 def get_chapter(self):
59 """
60 Returns the chapter of the book.
61 """
35 return self.chapter62 return self.chapter
63
36 def has_verselist(self):64 def has_verselist(self):
37 if self.verselist == {}:65 """
38 return False66 Returns whether or not the verse list contains verses.
39 else:67 """
40 return True68 return len(self.verselist) > 0
4169
42class BibleCommon:70
71class BibleCommon(object):
72 """
73 A common ancestor for bible download sites.
74 """
43 global log75 global log
44 log = logging.getLogger(u'BibleCommon')76 log = logging.getLogger(u'BibleCommon')
45 log.info(u'BibleCommon')77 log.info(u'BibleCommon')
78
46 def __init__(self):79 def __init__(self):
47 """80 """
81 An empty constructor... not sure why I'm here.
48 """82 """
83 pass
84
49 def _get_web_text(self, urlstring, proxyurl):85 def _get_web_text(self, urlstring, proxyurl):
86 """
87 Get the HTML from the web page.
88
89 ``urlstring``
90 The URL of the page to open.
91
92 ``proxyurl``
93 The URL of a proxy server used to access the Internet.
94 """
50 log.debug(u'get_web_text %s %s', proxyurl, urlstring)95 log.debug(u'get_web_text %s %s', proxyurl, urlstring)
51 if not proxyurl == None:96 if proxyurl is not None:
52 proxy_support = urllib2.ProxyHandler({'http': self.proxyurl})97 proxy_support = urllib2.ProxyHandler({'http': self.proxyurl})
53 http_support = urllib2.HTTPHandler()98 http_support = urllib2.HTTPHandler()
54 opener= urllib2.build_opener(proxy_support, http_support)99 opener = urllib2.build_opener(proxy_support, http_support)
55 urllib2.install_opener(opener)100 urllib2.install_opener(opener)
56 xml_string = u''101 xml_string = u''
57 req = urllib2.Request(urlstring)102 req = urllib2.Request(urlstring)
58 req.add_header(u'User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')103 req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
59 try:104 try:
60 handle = urllib2.urlopen(req)105 handle = urllib2.urlopen(req)
61 xml_string = unicode(handle.read())106 html = handle.read()
107 details = chardet.detect(html)
108 xml_string = unicode(html, details['encoding'])
62 except IOError, e:109 except IOError, e:
63 if hasattr(e, u'reason'):110 if hasattr(e, u'reason'):
64 log.error(u'Reason : ')111 log.error(u'Reason : %s', e.reason)
65 log.error( e.reason)
66 return xml_string112 return xml_string
67113
68 def _clean_text(self, text):114 def _clean_text(self, text):
69 """115 """
70 Clean up text and remove extra characters116 Clean up text and remove extra characters after been downloaded from
71 after been downloaded from web117 the Internet.
118
119 ``text``
120 The text from the web page that needs to be cleaned up.
72 """121 """
73 #return text.rstrip()122 #return text.rstrip()
74 # Remove Headings from the Text123 # Remove Headings from the Text
75 i = text.find(u'<h')124 start_tag = text.find(u'<h')
76 while i > -1:125 while start_tag > -1:
77 j=text.find(u'</h', i)126 end_tag = text.find(u'</h', start_tag)
78 text = text[ : (i - 1)]+text[(j+4)]127 text = text[:(start_tag - 1)] + text[(end_tag + 4)]
79 i = text.find(u'<h')128 start_tag = text.find(u'<h')
80
81 # Remove Support References from the Text129 # Remove Support References from the Text
82 x = text.find(u'<sup>')130 start_tag = text.find(u'<sup>')
83 while x > -1:131 while start_tag > -1:
84 y = text.find(u'</sup>')132 end_tag = text.find(u'</sup>')
85 text= text[:x] + text[y + 6:len(text)]133 text = text[:start_tag] + text[end_tag + 6:len(text)]
86 x = text.find(u'<sup>')134 start_tag = text.find(u'<sup>')
87
88 # Static Clean ups135 # Static Clean ups
89 text= text.replace(u'\n', u'')136 text = text.replace(u'\n', u'')
90 text= text.replace(u'\r', u'')137 text = text.replace(u'\r', u'')
91 text= text.replace(u'&nbsp;', u'')138 text = text.replace(u'&nbsp;', u'')
92 text= text.replace(u'<P>', u'')139 text = text.replace(u'<P>', u'')
93 text= text.replace(u'<I>', u'')140 text = text.replace(u'<I>', u'')
94 text= text.replace(u'</I>', u'')141 text = text.replace(u'</I>', u'')
95 text= text.replace(u'<P />', u'')142 text = text.replace(u'<P />', u'')
96 text= text.replace(u'<p />', u'')143 text = text.replace(u'<p />', u'')
97 text= text.replace(u'</P>', u'')144 text = text.replace(u'</P>', u'')
98 text= text.replace(u'<BR>', u'')145 text = text.replace(u'<BR>', u'')
99 text= text.replace(u'<BR />', u'')146 text = text.replace(u'<BR />', u'')
100 #text= text.replace(chr(189), u'1/2');print "l"147 #text = text.replace(chr(189), u'1/2');print "l"
101 text= text.replace(u'&quot;', "'")148 text = text.replace(u'&quot;', u'\"')
102 text= text.replace(u'&apos;', "'")149 text = text.replace(u'&apos;', u'\'')
103150 # Remove some other tags
104 i = text.find(u'<')151 start_tag = text.find(u'<')
105 while i > -1 :152 while start_tag > -1 :
106 j = text.find(u'>', i)153 end_tag = text.find(u'>', start_tag)
107 text= text[:i] + text[j+1:]154 text = text[:start_tag] + text[end_tag + 1:]
108 i = text.find(u'<')155 start_tag = text.find(u'<')
109156 text = text.replace(u'>', u'')
110 text= text.replace(u'>', u'')
111 return text.rstrip()157 return text.rstrip()
158