2008-11-19 18:13:22 +00:00
|
|
|
"""
|
|
|
|
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 urllib2
|
|
|
|
|
2008-12-06 09:33:46 +00:00
|
|
|
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
|
2008-11-19 18:13:22 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
class BibleOSISImpl():
|
|
|
|
global log
|
|
|
|
log=logging.getLogger("BibleOSISImpl")
|
|
|
|
log.info("BibleOSISImpl loaded")
|
2008-12-13 19:42:25 +00:00
|
|
|
def __init__(self, biblepath, bibledb):
|
2008-11-19 18:13:22 +00:00
|
|
|
self.bibledb = bibledb
|
2008-11-24 21:27:49 +00:00
|
|
|
self.booksOfBible = {} # books of the bible linked to bibleid {osis , name}
|
|
|
|
self.abbrevOfBible = {} # books of the bible linked to bibleid {osis ,Abbrev }
|
2008-12-13 19:42:25 +00:00
|
|
|
fbibles=open(biblepath+"/osisbooks_en.txt", 'r')
|
2008-11-24 21:27:49 +00:00
|
|
|
for line in fbibles:
|
|
|
|
p = line.split(",")
|
|
|
|
self.booksOfBible[p[0]] = p[1].replace('\n', '')
|
|
|
|
self.abbrevOfBible[p[0]] = p[2].replace('\n', '')
|
|
|
|
|
2008-11-19 18:13:22 +00:00
|
|
|
|
2008-12-16 17:29:39 +00:00
|
|
|
def load_data(self, osisfile, dialogobject=None):
|
|
|
|
self.bibledb.save_meta("Version", "Bible Version")
|
|
|
|
self.bibledb.save_meta("Copyright", "(c) Some Bible company")
|
|
|
|
self.bibledb.save_meta("Permission", "You Have Some")
|
2008-11-30 18:31:43 +00:00
|
|
|
|
2008-12-01 22:04:45 +00:00
|
|
|
#TODO: need to see if new / old or both testaments
|
2008-12-13 19:42:25 +00:00
|
|
|
dialogobject.setMax(65)
|
2008-12-01 22:04:45 +00:00
|
|
|
|
2008-11-19 18:13:22 +00:00
|
|
|
osis=open(osisfile, 'r')
|
|
|
|
|
|
|
|
book_ptr = ""
|
|
|
|
id = 0
|
|
|
|
verseText = "<verse osisID="
|
|
|
|
for f in osis.readlines():
|
|
|
|
#print f
|
|
|
|
s = f.find(verseText)
|
|
|
|
if s > -1: # we have a verse
|
|
|
|
e= f.find(">", s)
|
|
|
|
ref = f[s+15:e-1] # Book Reference
|
|
|
|
#lets find the bble text
|
|
|
|
s = e + 1 # find start of text
|
|
|
|
e = f.find("</verse>", s) # end of text
|
|
|
|
t = f[s:e]
|
|
|
|
#print s, e, f[s:e] # Found Basic Text
|
|
|
|
#remove tags of extra information
|
|
|
|
|
|
|
|
s = t.find("<FI>")
|
|
|
|
while s > -1:
|
|
|
|
e = t.find("<Fi>", s)
|
|
|
|
if e == -1: # TODO
|
|
|
|
#print "Y", s, e
|
|
|
|
s = -1
|
|
|
|
else:
|
|
|
|
t = t[:s] + t[e + 4: ]
|
|
|
|
s = t.find("<FI>")
|
|
|
|
|
|
|
|
s = t.find("<RF>")
|
|
|
|
while s > -1:
|
|
|
|
e = t.find("<Rf>", s)
|
|
|
|
t = t[:s] + t[e + 4: ]
|
|
|
|
#print "X", s, e, t
|
|
|
|
s = t.find("<RF>")
|
|
|
|
|
|
|
|
p = ref.split(".", 3) # split u[ the reference
|
|
|
|
if book_ptr != p[0]:
|
|
|
|
book_ptr = p[0]
|
2009-01-20 19:50:37 +00:00
|
|
|
id = self.bibledb.create_book(int(p[1]), self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]])
|
2008-11-30 18:31:43 +00:00
|
|
|
dialogobject.incrementBar()
|
2009-01-20 19:50:37 +00:00
|
|
|
self.bibledb.add_verse(id, p[1], p[2], t)
|
2008-11-19 18:13:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|