Initial version of crosswalk code

bzr-revno: 46
This commit is contained in:
Tim Bentley 2008-10-28 20:35:21 +00:00
parent ce883bc9ac
commit 2d1f84398d
2 changed files with 96 additions and 3 deletions

View File

@ -18,10 +18,10 @@ Place, Suite 330, Boston, MA 02111-1307 USA
import os, os.path import os, os.path
import sys import sys
mypath=os.path.split(os.path.abspath(__file__))[0] from urllib import FancyURLopener
sys.path.insert(0,(os.path.join(mypath, '..', '..')))
from openlp.utils import ConfigHelper class MyOpener(FancyURLopener):
version = "Googlebot/2.x (+http://www.googlebot.com/bot.html)"
class BibleHTTPImpl: class BibleHTTPImpl:
def __init__(self): def __init__(self):
@ -32,3 +32,54 @@ class BibleHTTPImpl:
Init confirms the bible exists and stores the database path. Init confirms the bible exists and stores the database path.
""" """
bible = {}
def getBibleChapter(self, version, book, chapter):
myopener = MyOpener()
urlstring = "http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word="+book+"+"+str(chapter)+"&version=niv"
page = myopener.open(urlstring)
#page = myopener.open("http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word=ge+1&version=niv")
xml_string = page.read()
#print xml_string
i= xml_string.find("NavCurrentChapter")
xml_string = xml_string[i:len(xml_string)]
i= xml_string.find("<TABLE")
xml_string = xml_string[i:len(xml_string)]
i= xml_string.find("<B>")
xml_string = xml_string[i + 3 :len(xml_string)] #remove the <B> at the front
i= xml_string.find("<B>") # Remove the heading for the book
xml_string = xml_string[i + 3 :len(xml_string)] #remove the <B> at the front
versePos = xml_string.find("<BLOCKQUOTE>")
#print versePos
bible = {}
cleanbible = {}
while versePos > 0:
versePos = xml_string.find("<B><I>", versePos) + 6
i = xml_string.find("</I></B>", versePos)
#print versePos, i
verse= xml_string[versePos:i] # Got the Chapter
#verse = int(temp)
#print "Chapter = " + str(temp)
versePos = i + 8 # move the starting position to negining of the text
i = xml_string.find("<B><I>", versePos) # fine the start of the next verse
if i == -1:
i = xml_string.find("</BLOCKQUOTE>",versePos)
verseText = xml_string[versePos: i]
versePos = 0
else:
#print i, versePos
verseText = xml_string[versePos: i]
versePos = i
bible[verse] = self._cleanVerse(verseText)
#print bible
return bible
def _cleanVerse(self, text):
text = text.replace('\n', '')
text = text.replace('\r', '')
text = text.replace('&nbsp;', '')
text = text.replace('<P>', '')
text = text.replace('"', '')
return text.rstrip()

View File

@ -0,0 +1,42 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import random
import unittest
import os, os.path
import sys
mypath=os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0,(os.path.join(mypath, '..', '..','..')))
from openlp.database.BibleManager import *
class TestHTTPBibleReader(unittest.TestCase):
def setUp(self):
self.bhi = BibleHTTPImpl()
def testGetBibleChapter(self):
# make sure the shuffled sequence does not lose any elements
print "testGetBibleChapter"
print self.bhi.getBibleChapter("NIV", "ge", 1)
print self.bhi.getBibleChapter("NIV", "re", 1)
if __name__ == '__main__':
unittest.main()