diff --git a/openlp/database/BibleDBImpl.py b/openlp/database/BibleDBImpl.py deleted file mode 100644 index 62d6b5231..000000000 --- a/openlp/database/BibleDBImpl.py +++ /dev/null @@ -1,213 +0,0 @@ -""" -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 os, os.path -import sys -import time -import datetime -import logging -import string - -from sqlalchemy import * -from sqlalchemy.sql import select -from sqlalchemy.orm import sessionmaker, mapper -mypath=os.path.split(os.path.abspath(__file__))[0] -sys.path.insert(0,(os.path.join(mypath, '..', '..'))) - -from openlp.utils import ConfigHelper - -logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s') - -metadata = MetaData() -#Define the tables and indexes -meta_table = Table('meta', metadata, - Column('key', String(255), primary_key=True), - Column('value', String(255)), -) - -testament_table = Table('testament', metadata, - Column('id', Integer, primary_key=True), - Column('name', String(30)), -) - -book_table = Table('book', metadata, - Column('id', Integer, primary_key=True), - Column('testament_id', None , ForeignKey('testament.id')), - Column('name', String(30)), - Column('abbrev', String(30)), -) -Index('idx_name', book_table.c.name, book_table.c.id) -Index('idx_abbrev', book_table.c.abbrev, book_table.c.id) - -verse_table = Table('verse', metadata, - Column('id', Integer, primary_key=True), - Column('book_id', None, ForeignKey('book.id')), - Column('chapter', Integer), - Column('verse', Integer), - Column('text', Text), -) -Index('idx_chapter_verse_book', verse_table.c.chapter, verse_table.c.verse, verse_table.c.book_id, verse_table.c.id) - -class BibleMeta(object): - def __init__(self, key, value): - self.key = key - self.value =value - - def __repr__(self): - return "" %(self.key, self.value) - -class Testament(object): - def __init__(self, name): - self.name = name - - def __repr__(self): - return "" %(self.name) - -class Book(object): - def __init__(self, testament_id, name, abbrev): - self.testament_id = testament_id - self.name = name - self.abbrev = abbrev - - def __repr__(self): - return "" %(self.id, self.testament_id, self.name, self.abbrev) - -class Verse(object): - def __init__(self, book_id, chapter, verse, text): - self.book_id = book_id - self.chapter = chapter - self.verse = verse - self.text = text - - def __repr__(self): - return "" %(self.book_id, self.chapter, self.verse, self.text) - -mapper(BibleMeta, meta_table) -mapper(Testament, testament_table) -mapper(Book, book_table) -mapper(Verse, verse_table) - -class BibleDBImpl: - def __init__(self, biblename): - # Connect to database - path = ConfigHelper.getBiblePath() - #print path - #print biblename - self.biblefile = os.path.join(path, biblename+".bible") - #print self.biblefile - self.db = create_engine("sqlite:///"+self.biblefile) - self.db.echo = False - #self.metadata = metaData() - metadata.bind = self.db - metadata.bind.echo = False - - def createTables(self): - if os.path.exists(self.biblefile): # delete bible file and set it up again - os.remove(self.biblefile) - meta_table.create() - testament_table.create() - book_table.create() - verse_table.create() - self.Session = sessionmaker() - self.Session.configure(bind=self.db) - - def loadData(self, booksfile, versesfile): - session = self.Session() - bmeta= BibleMeta("dbversion", "0.1") - session.add(bmeta) - bmeta= BibleMeta("version", "Bible Version") - session.add(bmeta) - bmeta= BibleMeta("Copyright", "(c) Some Bible company") - session.add(bmeta) - bmeta= BibleMeta("Permission", "You Have Some") - session.add(bmeta) - - - #Populate the Tables - testmeta = Testament(name="Old Testament") - session.add(testmeta) - testmeta = Testament(name="New Testament") - session.add(testmeta) - session.commit() - - fbooks=open(booksfile, 'r') - fverse=open(versesfile, 'r') - - for line in fbooks: - #print line - p = line.split(",") - p[2] = self._cleanText(p[2]) - p[3] = self._cleanText(p[3]) - bookmeta = Book(int(p[1]), p[2], p[3]) - session.add(bookmeta) - session.commit() - -# for row in session.query(Books).all(): -# print row - - book_ptr = "" - - for line in fverse: - #print line - p = line.split(",", 3) # split into 3 units and leave the rest as a single field - p[0] = self._cleanText(p[0]) - if book_ptr is not p[0]: - query = session.query(Book).filter(Book.name==p[0]) - #print query.first().id - book_ptr = p[0] - #print p[3] - versemeta = Verse(book_id=query.first().id, chapter=int(p[1]), verse=int(p[2]), text=self._cleanText(p[3])) - session.add(versemeta) - session.commit() - - - def getBibleText(self, bookname, chapter, verse): - s = text (""" select text FROM verse,book where verse.book_id == book.id AND verse.chapter == :c and verse.verse == :v and book.name == :b """) - return self.db.execute(s, c=chapter, v=verse , b=bookname).fetchone() - - def getBibleText(self, bookname, chapter, sverse, everse): - metadata.bind.echo = True - s = text (""" select text FROM verse,book where verse.book_id == book.id AND verse.chapter == :c AND (verse.verse between :v1 and :v2) and book.name == :b """) - return self.db.execute(s, c=chapter, v1=sverse , v2=everse, b=bookname).fetchall() - - def _cleanText(self, text): - text = text.replace('\n', '') - text = text.replace('\r', '') - text = text.replace('"', '') - return text - - - def Run_Tests(self): - metadata.bind.echo = True - print "test print" - session = self.Session() - print session.query(Book).filter(Book.name=='John').all() - q = session.query(Verse).filter(Verse.book_id==8) - print q.first() - - q = session.query(Verse, Book).filter(Verse.chapter==1).filter(Verse.verse==1).filter(Book.name=='Genesis') - print "--" - #print q.first()[0].text - #print q.first()[1].name - #print "----" - ch =1 - vs = 1 - bk = 'Genesis' - s = text (""" select text FROM verse,book where verse.book_id == book.id AND verse.chapter == :c and verse.verse == :v and book.name == :b """) - print self.db.execute(s, c=ch, v=vs , b=bk).fetchall() - - diff --git a/openlp/database/BibleHTTPImpl.py b/openlp/database/BibleHTTPImpl.py deleted file mode 100644 index 3c35af362..000000000 --- a/openlp/database/BibleHTTPImpl.py +++ /dev/null @@ -1,85 +0,0 @@ -""" -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 os, os.path -import sys -from urllib import FancyURLopener - -class MyOpener(FancyURLopener): - version = "Googlebot/2.x (+http://www.googlebot.com/bot.html)" - -class BibleHTTPImpl: - def __init__(self): - """ - Finds all the bibles defined for the system - Creates an Interface Object for each bible containing connection information - Throws Exception if no Bibles are found. - - 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("") - xml_string = xml_string[i + 3 :len(xml_string)] #remove the at the front - i= xml_string.find("") # Remove the heading for the book - xml_string = xml_string[i + 3 :len(xml_string)] #remove the at the front - versePos = xml_string.find("
") - #print versePos - bible = {} - cleanbible = {} - while versePos > 0: - versePos = xml_string.find("", versePos) + 6 - i = xml_string.find("", 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("", versePos) # fine the start of the next verse - if i == -1: - i = xml_string.find("
",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(' ', '') - text = text.replace('

', '') - text = text.replace('"', '') - - return text.rstrip() diff --git a/openlp/database/BibleManager.py b/openlp/database/BibleManager.py deleted file mode 100644 index 198f10249..000000000 --- a/openlp/database/BibleManager.py +++ /dev/null @@ -1,105 +0,0 @@ -""" -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 os, os.path -import sys -mypath=os.path.split(os.path.abspath(__file__))[0] -sys.path.insert(0,(os.path.join(mypath, '..', '..'))) - -from openlp.utils import ConfigHelper -from openlp.database.BibleDBImpl import * -from openlp.database.BibleHTTPImpl import * - -class BibleManager: - def __init__(self): - """ - Finds all the bibles defined for the system - Creates an Interface Object for each bible containing connection information - Throws Exception if no Bibles are found. - - Init confirms the bible exists and stores the database path. - """ - #if bible != "niv" and bible !="message": - # raise Exception('Unsupported bible requested ' + bible) - - self.biblelist = {} - self.biblePath = ConfigHelper.getBiblePath() - #print self.biblePath - files = os.listdir(self.biblePath) - for f in files: - b = f.split('.')[0] - self.biblelist[b] = BibleDBImpl(b) - #print self.biblelist - - def registerBible(self, name, biblesource, proxy, proxyport, proxyid, proxypass): - """ - Return a list of bibles from a given URL. - The selected Bible can then be registered and LazyLoaded into a database - """ - def registerBible(self, name, booksfile, versefile): - """ - Method to load a bible from a set of files into a database. - If the database exists it is deleted and the database is reloaded - from scratch. - """ - newbible = True - for b , o in self.biblelist.iteritems(): - print b - if b == name : - newbible = False - print "bible already registered" - if newbible == True : - nbible = BibleDBImpl(name) # Create new Bible - nbible.createTables() # Create Database - nbible.loadData(booksfile, versefile) - self.biblelist[name] = nbible - - def getBibles(self): - """ - Returns a list of Books of the bible - """ - r=[] - for b , o in self.biblelist.iteritems(): - r.append(b) - return r - - def getBibleBooks(self,bible): - """ - Returns a list of the books of the bible - """ - return ["Gen","Exd","Matt","Mark"] - - def getBookVerseCount(self, bible, book, chapter): - """ - Returns all the number of verses for a given - book and chapter - """ - return 28 - - def getVerseText(self, bible, book, chapter, sverse, everse = 0 ): - """ - Returns a list of verses for a given Book, Chapter and ranges of verses. - If the end verse(everse) is less then the start verse(sverse) - then only one verse is returned - """ - if everse < sverse: - text = self.biblelist[bible].getBibleText(book, chapter, sverse) - else: - text = self.biblelist[bible].getBibleText(book, chapter, sverse, everse) - print text - return text