forked from openlp/openlp
Updates to remove strange characters from strings
bzr-revno: 50
This commit is contained in:
parent
8f2da0e677
commit
dfcf566860
@ -124,10 +124,6 @@ class BibleDBImpl:
|
|||||||
verse_table.create()
|
verse_table.create()
|
||||||
self.Session = sessionmaker()
|
self.Session = sessionmaker()
|
||||||
self.Session.configure(bind=self.db)
|
self.Session.configure(bind=self.db)
|
||||||
# i1 = Index('idx_name', Books.c.name, Books.c.id)
|
|
||||||
# i1.create(bind=self.db)
|
|
||||||
# i2 = Index('idx_abbrev', Books.c.abbrev, Books.c.id)
|
|
||||||
# i2.create(bind=self.db)
|
|
||||||
|
|
||||||
def loadData(self, booksfile, versesfile):
|
def loadData(self, booksfile, versesfile):
|
||||||
session = self.Session()
|
session = self.Session()
|
||||||
@ -154,6 +150,8 @@ class BibleDBImpl:
|
|||||||
for line in fbooks:
|
for line in fbooks:
|
||||||
#print line
|
#print line
|
||||||
p = line.split(",")
|
p = line.split(",")
|
||||||
|
p[2] = self._cleanText(p[2])
|
||||||
|
p[3] = self._cleanText(p[3])
|
||||||
bookmeta = Book(int(p[1]), p[2], p[3])
|
bookmeta = Book(int(p[1]), p[2], p[3])
|
||||||
session.add(bookmeta)
|
session.add(bookmeta)
|
||||||
session.commit()
|
session.commit()
|
||||||
@ -166,12 +164,13 @@ class BibleDBImpl:
|
|||||||
for line in fverse:
|
for line in fverse:
|
||||||
#print line
|
#print line
|
||||||
p = line.split(",", 3) # split into 3 units and leave the rest as a single field
|
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]:
|
if book_ptr is not p[0]:
|
||||||
query = session.query(Book).filter(Book.name==p[0])
|
query = session.query(Book).filter(Book.name==p[0])
|
||||||
#print query.first().id
|
#print query.first().id
|
||||||
book_ptr = p[0]
|
book_ptr = p[0]
|
||||||
#print p[3]
|
#print p[3]
|
||||||
versemeta = Verse(book_id=query.first().id, chapter=int(p[1]), verse=int(p[2]), text=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.add(versemeta)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
@ -180,22 +179,29 @@ class BibleDBImpl:
|
|||||||
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 """)
|
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()
|
return self.db.execute(s, c=chapter, v=verse , b=bookname).fetchone()
|
||||||
|
|
||||||
|
def _cleanText(self, text):
|
||||||
|
text = text.replace('\n', '')
|
||||||
|
text = text.replace('\r', '')
|
||||||
|
text = text.replace('"', '')
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def Run_Tests(self):
|
def Run_Tests(self):
|
||||||
metadata.bind.echo = True
|
metadata.bind.echo = True
|
||||||
print "test print"
|
print "test print"
|
||||||
session = self.Session()
|
session = self.Session()
|
||||||
print session.query(Book).filter(Book.name=='"John"').all()
|
print session.query(Book).filter(Book.name=='John').all()
|
||||||
q = session.query(Verse).filter(Verse.book_id==8)
|
q = session.query(Verse).filter(Verse.book_id==8)
|
||||||
print q.first().text
|
print q.first()
|
||||||
|
|
||||||
q = session.query(Verse, Book).filter(Verse.chapter==1).filter(Verse.verse==1).filter(Book.name=='"Genesis"')
|
q = session.query(Verse, Book).filter(Verse.chapter==1).filter(Verse.verse==1).filter(Book.name=='Genesis')
|
||||||
print "--"
|
print "--"
|
||||||
print q.first()[0].text
|
#print q.first()[0].text
|
||||||
print q.first()[1].name
|
#print q.first()[1].name
|
||||||
print "----"
|
#print "----"
|
||||||
ch =1
|
ch =1
|
||||||
vs = 1
|
vs = 1
|
||||||
bk = '"Genesis"'
|
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 """)
|
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()
|
print self.db.execute(s, c=ch, v=vs , b=bk).fetchall()
|
||||||
|
|
||||||
|
@ -91,12 +91,14 @@ class BibleManager:
|
|||||||
"""
|
"""
|
||||||
return 28
|
return 28
|
||||||
|
|
||||||
def getVerseText(self, bible,book, chapter, sverse, everse):
|
def getVerseText(self, bible, book, chapter, sverse, everse = 0 ):
|
||||||
"""
|
"""
|
||||||
Returns a list of verses for a given Book, Chapter and ranges of verses.
|
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)
|
If the end verse(everse) is less then the start verse(sverse)
|
||||||
then only one verse is returned
|
then only one verse is returned
|
||||||
"""
|
"""
|
||||||
if everse < sverse:
|
if everse < sverse:
|
||||||
|
everse = sverse # make sure end after we start. Also optional
|
||||||
text = self.biblelist[bible].getBibleText(book, chapter, sverse)
|
text = self.biblelist[bible].getBibleText(book, chapter, sverse)
|
||||||
|
print text
|
||||||
return text
|
return text
|
||||||
|
Loading…
Reference in New Issue
Block a user