forked from openlp/openlp
Add ability register a bible to down load via proxy server
bzr-revno: 90
This commit is contained in:
parent
a9f110cd6c
commit
00c105a9f9
@ -45,7 +45,15 @@ class BibleHTTPImpl(BibleCommon):
|
||||
"""
|
||||
bible = {}
|
||||
biblesource = ""
|
||||
proxyurl = None
|
||||
|
||||
def setProxy(self,proxyurl):
|
||||
"""
|
||||
Set the Proxy Url
|
||||
"""
|
||||
log.debug("setProxy %s", proxyurl)
|
||||
self.proxyurl = proxyurl
|
||||
|
||||
def setBibleSource(self,biblesource):
|
||||
"""
|
||||
Set the source of where the bible text is comming from
|
||||
@ -77,7 +85,13 @@ class BibleHTTPImpl(BibleCommon):
|
||||
|
||||
"""
|
||||
version = 49
|
||||
log.debug( "getBibleBGChapter %s,%s,%s,%s", version, bookid, bookname, chapter)
|
||||
log.debug( "getBibleBGChapter %s,%s,%s,%s", version, bookid, bookname, chapter)
|
||||
if self.proxyurl != None:
|
||||
proxy_support = urllib2.ProxyHandler({'http': self.proxyurl})
|
||||
http_support = urllib2.HTTPHandler()
|
||||
opener= urllib2.build_opener(proxy_support, http_support)
|
||||
urllib2.install_opener(opener)
|
||||
|
||||
urlstring = "http://www.biblegateway.com/passage/?book_id="+str(bookid)+"&chapter"+str(chapter)+"&version="+str(version)
|
||||
log.debug( "Url String %s", urlstring)
|
||||
xml_string = ""
|
||||
|
@ -64,9 +64,11 @@ class BibleManager(Plugin):
|
||||
self.bibleDBCache[b] = BibleDBImpl(b)
|
||||
biblesource = self.bibleDBCache[b].getMeta("WEB") # look to see if lazy load bible exists and get create getter.
|
||||
if biblesource:
|
||||
nhttp = BibleHTTPImpl()
|
||||
nhttp.setBibleSource(biblesource) # tell The Server where to get the verses from.
|
||||
self.bibleHTTPCache[b] = nhttp
|
||||
nhttp = BibleHTTPImpl()
|
||||
nhttp.setBibleSource(biblesource) # tell The Server where to get the verses from.
|
||||
self.bibleHTTPCache[b] = nhttp
|
||||
proxy = self.bibleDBCache[b].getMeta("proxy") # look to see if lazy load bible exists and get create getter.
|
||||
nhttp.setProxy(proxy) # tell The Server where to get the verses from.
|
||||
#
|
||||
#Load in memory objects
|
||||
for line in fbibles:
|
||||
@ -88,12 +90,12 @@ class BibleManager(Plugin):
|
||||
#log.debug( self.bibleHTTPCache )
|
||||
log.debug( "Bible Initialised")
|
||||
|
||||
def registerHTTPBible(self, biblename, biblesource, proxy, proxyport, proxyid, proxypass):
|
||||
def registerHTTPBible(self, biblename, biblesource, proxyurl=None, proxyid=None, proxypass=None):
|
||||
"""
|
||||
Return a list of bibles from a given URL.
|
||||
The selected Bible can then be registered and LazyLoaded into a database
|
||||
"""
|
||||
log.debug( "registerHTTPBible %s,%s,%s,%s,%s,%s", biblename, biblesource, proxy, proxyport, proxyid, proxypass)
|
||||
log.debug( "registerHTTPBible %s,%s,%s,%s,%s", biblename, biblesource, proxyurl, proxyid, proxypass)
|
||||
if self._isNewBible(biblename):
|
||||
nbible = BibleDBImpl(biblename) # Create new Bible
|
||||
nbible.createTables() # Create Database
|
||||
@ -103,6 +105,14 @@ class BibleManager(Plugin):
|
||||
nhttp.setBibleSource(biblesource)
|
||||
self.bibleHTTPCache[biblename] = nhttp
|
||||
nbible.loadMeta("WEB", biblesource) # register a lazy loading interest
|
||||
if proxyurl != None:
|
||||
nbible.loadMeta("proxy", proxyurl) # store the proxy URL
|
||||
nhttp.setProxy(proxyurl)
|
||||
if proxyid != None:
|
||||
nbible.loadMeta("proxyid", proxyid) # store the proxy userid
|
||||
if proxypass != None:
|
||||
nbible.loadMeta("proxypass", proxypass) # store the proxy password
|
||||
|
||||
|
||||
def registerFileBible(self, biblename, booksfile, versefile):
|
||||
"""
|
||||
|
@ -63,8 +63,9 @@ class TestBibleManager:
|
||||
def testRegisterBibleHTTP(self):
|
||||
# Register a bible from files
|
||||
log.debug( "\n.......testRegisterBibleHTTP")
|
||||
self.bm.registerHTTPBible("asv","Crosswalk", "", "", "", "")
|
||||
self.bm.registerHTTPBible("nasb","Biblegateway", "", "", "", "")
|
||||
self.bm.registerHTTPBible("asv","Crosswalk", "", "", "")
|
||||
self.bm.registerHTTPBible("nasb","Biblegateway", "", "", "")
|
||||
self.bm.registerHTTPBible("nkj","Biblegateway", "http://tigger2:3128/", "", "")
|
||||
b = self.bm.getBibles()
|
||||
for b1 in b:
|
||||
log.debug( b1)
|
||||
@ -99,18 +100,21 @@ class TestBibleManager:
|
||||
|
||||
def testGetVerseText(self):
|
||||
log.debug( "\n.......testGetVerseText")
|
||||
#c = self.bm.getVerseText("TheMessage",'Genesis',1,2,1)
|
||||
#log.debug( c )
|
||||
#c = self.bm.getVerseText('NIV','Genesis',1,1,2)
|
||||
#log.debug( c )
|
||||
c = self.bm.getVerseText("TheMessage",'Genesis',1,2,1)
|
||||
log.debug( c )
|
||||
c = self.bm.getVerseText('NIV','Genesis',1,1,2)
|
||||
log.debug( c )
|
||||
c = self.bm.getVerseText('asv','Revelation',1,1,2)
|
||||
log.debug( c )
|
||||
c = self.bm.getVerseText('asv','Revelation',1,5,9)
|
||||
log.debug( c )
|
||||
c = self.bm.getVerseText('nasb','Revelation',10,5,9)
|
||||
log.debug( c )
|
||||
log.debug( c )
|
||||
c = self.bm.getVerseText('nkj','Revelation',10,5,9)
|
||||
log.debug( c )
|
||||
|
||||
def testLoadBible(self):
|
||||
log.debug( "\n.......testLoadBible")
|
||||
self.bm.loadBible('asv')
|
||||
self.bm.loadBible('nasb')
|
||||
#self.bm.loadBible('asv')
|
||||
#self.bm.loadBible('nasb')
|
||||
#self.bm.loadBible('nkj')
|
||||
|
Loading…
Reference in New Issue
Block a user