rename httpbooks.sqlite to bibles_resources.sqlite and change database scheme

moved the content of biblegateway.csv, bibleserver.csv and crosswalkbooks.csv into bibles_resources.sqlite
adapt loadWebBibles() process according to the changes above
remove class HTTPBible from http.py and add the functions to a new class BiblesResourcesDB in db.py which now handels the reading of bibles_resources.sqlite
This commit is contained in:
Armin Köhler 2011-03-12 11:23:42 +01:00
parent 4c8cc928b9
commit e52a80c9c3
8 changed files with 210 additions and 319 deletions

View File

@ -39,6 +39,7 @@ from openlp.core.lib.ui import UiStrings, critical_error_message_box
from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
from openlp.core.utils import AppLocation, string_is_unicode
from openlp.plugins.bibles.lib.manager import BibleFormat
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
log = logging.getLogger(__name__)
@ -634,46 +635,27 @@ class BibleImportForm(OpenLPWizard):
"""
Load the lists of Crosswalk, BibleGateway and Bibleserver bibles.
"""
filepath = AppLocation.get_directory(AppLocation.PluginsDir)
filepath = os.path.join(filepath, u'bibles', u'resources')
# Load Crosswalk Bibles.
self.loadBibleResourceFile(
os.path.join(filepath, u'crosswalkbooks.csv'),
WebDownload.Crosswalk)
self.loadBibleResource(WebDownload.Crosswalk)
# Load BibleGateway Bibles.
self.loadBibleResourceFile(os.path.join(filepath, u'biblegateway.csv'),
WebDownload.BibleGateway)
self.loadBibleResource(WebDownload.BibleGateway)
# Load and Bibleserver Bibles.
self.loadBibleResourceFile(os.path.join(filepath, u'bibleserver.csv'),
WebDownload.Bibleserver)
self.loadBibleResource(WebDownload.Bibleserver)
def loadBibleResourceFile(self, file_path_name, download_type):
def loadBibleResource(self, download_type):
"""
Loads a web bible resource file.
``file_path_name``
The file to load including the file's path.
Loads a web bible from bible_resources.sqlite.
``download_type``
The WebDownload type this file is for.
The WebDownload type e.g. bibleserver.
"""
self.web_bible_list[download_type] = {}
books_file = None
try:
books_file = open(file_path_name, 'rb')
dialect = csv.Sniffer().sniff(books_file.read(1024))
books_file.seek(0)
books_reader = csv.reader(books_file, dialect)
for line in books_reader:
ver = string_is_unicode(line[0])
name = string_is_unicode(line[1])
self.web_bible_list[download_type][ver] = name.strip()
except IOError:
log.exception(u'%s resources missing' %
WebDownload.Names[download_type])
finally:
if books_file:
books_file.close()
bibles = BiblesResourcesDB.get_webbibles(
WebDownload.Names[download_type])
for bible in bibles:
ver = bible[u'name']
name = bible[u'abbreviation']
self.web_bible_list[download_type][ver] = name.strip()
def preWizard(self):
"""

View File

@ -26,7 +26,9 @@
import logging
import chardet
import os
import re
import sqlite3
from PyQt4 import QtCore
from sqlalchemy import Column, ForeignKey, or_, Table, types
@ -36,6 +38,7 @@ from sqlalchemy.orm.exc import UnmappedClassError
from openlp.core.lib import Receiver, translate
from openlp.core.lib.db import BaseModel, init_db, Manager
from openlp.core.lib.ui import critical_error_message_box
from openlp.core.utils import AppLocation
log = logging.getLogger(__name__)
@ -444,3 +447,192 @@ class BibleDB(QtCore.QObject, Manager):
log.debug(u'...............................Verses ')
verses = self.session.query(Verse).all()
log.debug(verses)
class BiblesResourcesDB(QtCore.QObject, Manager):
"""
This class represents the database-bound Bible Resources. It provide
some resources which are used in the Bibles plugin.
A wrapper class around a small SQLite database which contains the download
resources, a biblelist from the different download resources, the books,
chapter counts and verse counts for the web download Bibles, a language
reference, the testament reference and some basic spelling variants. This
class contains a singleton "cursor" so that only one connection to the
SQLite database is ever used.
"""
cursor = None
@staticmethod
def get_cursor():
"""
Return the cursor object. Instantiate one if it doesn't exist yet.
"""
if BiblesResourcesDB.cursor is None:
filepath = os.path.join(
AppLocation.get_directory(AppLocation.PluginsDir), u'bibles',
u'resources', u'bibles_resources.sqlite')
conn = sqlite3.connect(filepath)
BiblesResourcesDB.cursor = conn.cursor()
return BiblesResourcesDB.cursor
@staticmethod
def run_sql(query, parameters=()):
"""
Run an SQL query on the database, returning the results.
``query``
The actual SQL query to run.
``parameters``
Any variable parameters to add to the query.
"""
cursor = BiblesResourcesDB.get_cursor()
cursor.execute(query, parameters)
return cursor.fetchall()
@staticmethod
def get_books():
"""
Return a list of all the books of the Bible.
"""
books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, '
u'abbreviation, chapters FROM book_reference ORDER BY id')
book_list = []
for book in books:
book_list.append({
u'id': book[0],
u'testament_id': book[1],
u'name': unicode(book[2]),
u'abbreviation': unicode(book[3]),
u'chapters': book[4]
})
return book_list
@staticmethod
def get_book(name):
"""
Return a book by name or abbreviation.
``name``
The name or abbreviation of the book.
"""
if not isinstance(name, unicode):
name = unicode(name)
name = name.title()
books = BiblesResourcesDB.run_sql(u'SELECT id, testament_id, name, '
u'abbreviation, chapters FROM book_reference WHERE name = ? OR '
u'abbreviation = ?', (name, name))
if books:
return {
u'id': books[0][0],
u'testament_id': books[0][1],
u'name': unicode(books[0][2]),
u'abbreviation': unicode(books[0][3]),
u'chapters': books[0][4]
}
else:
return None
@staticmethod
def get_chapter(name, chapter):
"""
Return the chapter details for a specific chapter of a book.
``name``
The name or abbreviation of a book.
``chapter``
The chapter number.
"""
if not isinstance(name, int):
chapter = int(chapter)
book = BiblesResourcesDB.get_book(name)
chapters = BiblesResourcesDB.run_sql(u'SELECT id, book_reference_id, '
u'chapter, verse_count FROM chapters WHERE book_reference_id = ?',
(book[u'id'],))
if chapters:
return {
u'id': chapters[chapter-1][0],
u'book_reference_id': chapters[chapter-1][1],
u'chapter': chapters[chapter-1][2],
u'verse_count': chapters[chapter-1][3]
}
else:
return None
@staticmethod
def get_chapter_count(book):
"""
Return the number of chapters in a book.
``book``
The name or abbreviation of the book.
"""
details = BiblesResourcesDB.get_book(book)
if details:
return details[u'chapters']
return 0
@staticmethod
def get_verse_count(book, chapter):
"""
Return the number of verses in a chapter.
``book``
The name or abbreviation of the book.
``chapter``
The number of the chapter.
"""
details = BiblesResourcesDB.get_chapter(book, chapter)
if details:
return details[u'verse_count']
return 0
@staticmethod
def get_download_source(source):
"""
Return a download_source by source.
``name``
The name or abbreviation of the book.
"""
if not isinstance(source, unicode):
source = unicode(source)
source = source.title()
#source = source.lower()
log.debug(u'Test: %s' % source)
dl_source = BiblesResourcesDB.run_sql(u'SELECT id, source FROM '
u'download_source WHERE source = ?', (source.lower(),))
if dl_source:
return {
u'id': dl_source[0][0],
u'source': dl_source[0][1]
}
else:
return None
@staticmethod
def get_webbibles(source):
"""
Return the chapter details for a specific chapter of a book.
``name``
The name of the webbible.
"""
if not isinstance(source, unicode):
source = unicode(source)
source = BiblesResourcesDB.get_download_source(source)
bibles = BiblesResourcesDB.run_sql(u'SELECT id, name, abbreviation, '
u'language_id, download_source_id FROM webbibles WHERE '
u'download_source_id = ?', (source[u'id'],))
bibles_temp = []
for bible in bibles:
bibles_temp.append({
u'id': bible[0],
u'name': bible[1],
u'abbreviation': bible[2],
u'language_id': bible[3],
u'download_source_id': bible[4]
})
return bibles_temp

View File

@ -41,146 +41,10 @@ from openlp.core.lib import Receiver, translate
from openlp.core.lib.ui import critical_error_message_box
from openlp.core.utils import AppLocation, get_web_page
from openlp.plugins.bibles.lib import SearchResults
from openlp.plugins.bibles.lib.db import BibleDB, Book
from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB, Book
log = logging.getLogger(__name__)
class HTTPBooks(object):
"""
A wrapper class around a small SQLite database which contains the books,
chapter counts and verse counts for the web download Bibles. This class
contains a singleton "cursor" so that only one connection to the SQLite
database is ever used.
"""
cursor = None
@staticmethod
def get_cursor():
"""
Return the cursor object. Instantiate one if it doesn't exist yet.
"""
if HTTPBooks.cursor is None:
filepath = os.path.join(
AppLocation.get_directory(AppLocation.PluginsDir), u'bibles',
u'resources', u'httpbooks.sqlite')
conn = sqlite3.connect(filepath)
HTTPBooks.cursor = conn.cursor()
return HTTPBooks.cursor
@staticmethod
def run_sql(query, parameters=()):
"""
Run an SQL query on the database, returning the results.
``query``
The actual SQL query to run.
``parameters``
Any variable parameters to add to the query.
"""
cursor = HTTPBooks.get_cursor()
cursor.execute(query, parameters)
return cursor.fetchall()
@staticmethod
def get_books():
"""
Return a list of all the books of the Bible.
"""
books = HTTPBooks.run_sql(u'SELECT id, testament_id, name, '
u'abbreviation, chapters FROM books ORDER BY id')
book_list = []
for book in books:
book_list.append({
u'id': book[0],
u'testament_id': book[1],
u'name': unicode(book[2]),
u'abbreviation': unicode(book[3]),
u'chapters': book[4]
})
return book_list
@staticmethod
def get_book(name):
"""
Return a book by name or abbreviation.
``name``
The name or abbreviation of the book.
"""
if not isinstance(name, unicode):
name = unicode(name)
name = name.title()
books = HTTPBooks.run_sql(u'SELECT id, testament_id, name, '
u'abbreviation, chapters FROM books WHERE name = ? OR '
u'abbreviation = ?', (name, name))
if books:
return {
u'id': books[0][0],
u'testament_id': books[0][1],
u'name': unicode(books[0][2]),
u'abbreviation': unicode(books[0][3]),
u'chapters': books[0][4]
}
else:
return None
@staticmethod
def get_chapter(name, chapter):
"""
Return the chapter details for a specific chapter of a book.
``name``
The name or abbreviation of a book.
``chapter``
The chapter number.
"""
if not isinstance(name, int):
chapter = int(chapter)
book = HTTPBooks.get_book(name)
chapters = HTTPBooks.run_sql(u'SELECT id, book_id, chapter, '
u'verses FROM chapters WHERE book_id = ?', (book[u'id'],))
if chapters:
return {
u'id': chapters[chapter-1][0],
u'book_id': chapters[chapter-1][1],
u'chapter': chapters[chapter-1][2],
u'verses': chapters[chapter-1][3]
}
else:
return None
@staticmethod
def get_chapter_count(book):
"""
Return the number of chapters in a book.
``book``
The name or abbreviation of the book.
"""
details = HTTPBooks.get_book(book)
if details:
return details[u'chapters']
return 0
@staticmethod
def get_verse_count(book, chapter):
"""
Return the number of verses in a chapter.
``book``
The name or abbreviation of the book.
``chapter``
The number of the chapter.
"""
details = HTTPBooks.get_chapter(book, chapter)
if details:
return details[u'verses']
return 0
class BGExtract(object):
"""
Extract verses from BibleGateway
@ -447,7 +311,7 @@ class HTTPBible(BibleDB):
book = reference[0]
db_book = self.get_book(book)
if not db_book:
book_details = HTTPBooks.get_book(book)
book_details = BiblesResourcesDB.get_book(book)
if not book_details:
critical_error_message_box(
translate('BiblesPlugin', 'No Book Found'),
@ -497,13 +361,13 @@ class HTTPBible(BibleDB):
Return the list of books.
"""
return [Book.populate(name=book['name'])
for book in HTTPBooks.get_books()]
for book in BiblesResourcesDB.get_books()]
def get_chapter_count(self, book):
"""
Return the number of chapters in a particular book.
"""
return HTTPBooks.get_chapter_count(book)
return BiblesResourcesDB.get_chapter_count(book)
def get_verse_count(self, book, chapter):
"""
@ -515,7 +379,7 @@ class HTTPBible(BibleDB):
``chapter``
The chapter whose verses are being counted.
"""
return HTTPBooks.get_verse_count(book, chapter)
return BiblesResourcesDB.get_verse_count(book, chapter)
def get_soup_for_bible_ref(reference_url, header=None, pre_parse_regex=None,
pre_parse_substitute=None, cleaner=None):

View File

@ -1,81 +0,0 @@
João Ferreira de Almeida Atualizada,AA
التفسير التطبيقى للكتاب المقدس,ALAB
Shqip,ALB
Amplified Bible,AMP
Amuzgo de Guerrero,AMU
American Standard Version,ASV
La Bible du Semeur,BDS
Български 1940,BG1940
Български,BULG
Chinanteco de Comaltepec,CCO
Contemporary English Version,CEV
Cakchiquel Occidental,CKW
Hrvatski,CRO
Castilian,CST
聖經和合本 (简体中文),CUVS
聖經和合本 (繁体中文),CUV
Darby Translation,DARBY
Dette er Biblen på dansk,DN1933
Det Norsk Bibelselskap 1930,DNB1930
English Standard Version,ESV
GODS WORD Translation,GW
Holman Christian Standard Bible,HCSB
Kreyòl ayisyen bib,HCV
Hiligaynon Bible,HLGN
Hoffnung für Alle,HOF
Het Boek,HTB
Icelandic Bible,ICELAND
Jacalteco Oriental,JAC
Károlyi-biblia,KAR
Kekchi,KEK
21st Century King James Version,KJ21
King James Version,KJV
La Biblia de las Américas,LBLA
Levande Bibeln,LB
La Parola è Vita,LM
La Nuova Diodati,LND
Louis Segond,LSG
Luther Bibel 1545,LUTH1545
Māori Bible,MAORI
Македонски Новиот Завет,MNT
The Message,MSG
Mam de Comitancillo Central,MVC
Mam de Todos Santos Cuchumatán,MVJ
New American Standard Bible,NASB
New Century Version,NCV
Náhuatl de Guerrero,NGU
New International Reader's Version,NIRV
New International Version 1984,NIV1984
New International Version 2010,NIV
New International Version - UK,NIVUK
New King James Version,NKJV
New Living Translation,NLT
Nádej pre kazdého,NPK
Nueva Versión Internacional,NVI
O Livro,OL
Quiché Centro Occidental,QUT
Reimer 2001,REIMER
Română Cornilescu,RMNN
Новый перевод на русский язык,RUSV
Reina-Valera Antigua,RVA
Reina-Valera 1960,RVR1960
Reina-Valera 1995,RVR1995
Slovo na cestu,SNC
Ang Salita ng Diyos,SND
Swahili New Testament,SNT
Svenska 1917,SV1917
Levande Bibeln,SVL
Создать страницу,SZ
Traducción en lenguaje actual,TLA
New Romanian Translation,TLCR
Todays New International Version 2005,TNIV
Textus Receptus Stephanus 1550,TR1550
Textus Receptus Scrivener 1894,TR1894
Українська Біблія. Переклад Івана Огієнка,UKR
Uspanteco,USP
Kinh Thánh tiếng Việt 1934,VIET
Worldwide English (New Testament),WE
Codex Vaticanus Westcott-Hort 1881,WHNU
Westminster Leningrad Codex,WLC
Wycliffe New Testament,WYC
Young's Literal Translation,YLT
1 João Ferreira de Almeida Atualizada AA
2 التفسير التطبيقى للكتاب المقدس ALAB
3 Shqip ALB
4 Amplified Bible AMP
5 Amuzgo de Guerrero AMU
6 American Standard Version ASV
7 La Bible du Semeur BDS
8 Български 1940 BG1940
9 Български BULG
10 Chinanteco de Comaltepec CCO
11 Contemporary English Version CEV
12 Cakchiquel Occidental CKW
13 Hrvatski CRO
14 Castilian CST
15 聖經和合本 (简体中文) CUVS
16 聖經和合本 (繁体中文) CUV
17 Darby Translation DARBY
18 Dette er Biblen på dansk DN1933
19 Det Norsk Bibelselskap 1930 DNB1930
20 English Standard Version ESV
21 GOD’S WORD Translation GW
22 Holman Christian Standard Bible HCSB
23 Kreyòl ayisyen bib HCV
24 Hiligaynon Bible HLGN
25 Hoffnung für Alle HOF
26 Het Boek HTB
27 Icelandic Bible ICELAND
28 Jacalteco – Oriental JAC
29 Károlyi-biblia KAR
30 Kekchi KEK
31 21st Century King James Version KJ21
32 King James Version KJV
33 La Biblia de las Américas LBLA
34 Levande Bibeln LB
35 La Parola è Vita LM
36 La Nuova Diodati LND
37 Louis Segond LSG
38 Luther Bibel 1545 LUTH1545
39 Māori Bible MAORI
40 Македонски Новиот Завет MNT
41 The Message MSG
42 Mam de Comitancillo Central MVC
43 Mam de Todos Santos Cuchumatán MVJ
44 New American Standard Bible NASB
45 New Century Version NCV
46 Náhuatl de Guerrero NGU
47 New International Reader's Version NIRV
48 New International Version 1984 NIV1984
49 New International Version 2010 NIV
50 New International Version - UK NIVUK
51 New King James Version NKJV
52 New Living Translation NLT
53 Nádej pre kazdého NPK
54 Nueva Versión Internacional NVI
55 O Livro OL
56 Quiché – Centro Occidental QUT
57 Reimer 2001 REIMER
58 Română Cornilescu RMNN
59 Новый перевод на русский язык RUSV
60 Reina-Valera Antigua RVA
61 Reina-Valera 1960 RVR1960
62 Reina-Valera 1995 RVR1995
63 Slovo na cestu SNC
64 Ang Salita ng Diyos SND
65 Swahili New Testament SNT
66 Svenska 1917 SV1917
67 Levande Bibeln SVL
68 Создать страницу SZ
69 Traducción en lenguaje actual TLA
70 New Romanian Translation TLCR
71 Today’s New International Version 2005 TNIV
72 Textus Receptus Stephanus 1550 TR1550
73 Textus Receptus Scrivener 1894 TR1894
74 Українська Біблія. Переклад Івана Огієнка UKR
75 Uspanteco USP
76 Kinh Thánh tiếng Việt 1934 VIET
77 Worldwide English (New Testament) WE
78 Codex Vaticanus Westcott-Hort 1881 WHNU
79 Westminster Leningrad Codex WLC
80 Wycliffe New Testament WYC
81 Young's Literal Translation YLT

View File

@ -1,39 +0,0 @@
عربي, ARA
Bible překlad 21. století, B21
Bible du Semeur, BDS
Българската Библия, BLG
Český ekumenický překlad, CEP
Hrvatski, CRO
Священное Писание, CRS
Version La Biblia al Dia, CST
中文和合本(简体), CUVS
Bibelen på hverdagsdansk, DK
Revidierte Elberfelder, ELB
Einheitsübersetzung, EU
Gute Nachricht Bibel, GNB
Hoffnung für alle, HFA
Hungarian, HUN
Het Boek, HTB
La Parola è Vita, ITA
IBS-fordítás (Új Károli), KAR
King James Version, KJV
Luther 1984, LUT
Septuaginta, LXX
Neue Genfer Übersetzung, NGU
New International Readers Version, NIRV
New International Version, NIV
Neues Leben, NL
En Levende Bok (NOR), NOR
Nádej pre kazdého, NPK
Noua traducere în limba românã, NTR
Nueva Versión Internacional, NVI
הברית הישנה, OT
Słowo Życia, POL
O Livro, PRT
Новый перевод на русский язык, RUS
Slovo na cestu, SNC
Schlachter 2000, SLT
En Levande Bok (SWE), SVL
Today's New International Version, TNIV
Türkçe, TR
Biblia Vulgata, VUL
1 عربي ARA
2 Bible – překlad 21. století B21
3 Bible du Semeur BDS
4 Българската Библия BLG
5 Český ekumenický překlad CEP
6 Hrvatski CRO
7 Священное Писание CRS
8 Version La Biblia al Dia CST
9 中文和合本(简体) CUVS
10 Bibelen på hverdagsdansk DK
11 Revidierte Elberfelder ELB
12 Einheitsübersetzung EU
13 Gute Nachricht Bibel GNB
14 Hoffnung für alle HFA
15 Hungarian HUN
16 Het Boek HTB
17 La Parola è Vita ITA
18 IBS-fordítás (Új Károli) KAR
19 King James Version KJV
20 Luther 1984 LUT
21 Septuaginta LXX
22 Neue Genfer Übersetzung NGU
23 New International Readers Version NIRV
24 New International Version NIV
25 Neues Leben NL
26 En Levende Bok (NOR) NOR
27 Nádej pre kazdého NPK
28 Noua traducere în limba românã NTR
29 Nueva Versión Internacional NVI
30 הברית הישנה OT
31 Słowo Życia POL
32 O Livro PRT
33 Новый перевод на русский язык RUS
34 Slovo na cestu SNC
35 Schlachter 2000 SLT
36 En Levande Bok (SWE) SVL
37 Today's New International Version TNIV
38 Türkçe TR
39 Biblia Vulgata VUL

View File

@ -1,27 +0,0 @@
New American Standard,nas
American Standard Version,asv
English Standard Version,esv
New King James Version,nkj
King James Version,kjv
Holman Christian Standard Bible,csb
Third Millennium Bible,tmb
New International Version,niv
New Living Translation,nlt
New Revised Standard,nrs
Revised Standard Version,rsv
Good News Translation,gnt
Douay-Rheims Bible,rhe
The Message,msg
The Complete Jewish Bible,cjb
New Century Version,ncv
GOD'S WORD Translation,gwd
Hebrew Names Version,hnv
World English Bible,web
The Bible in Basic English,bbe
Young's Literal Translation,ylt
Today's New International Version,tnv
New International Reader's Version,nrv
The Darby Translation,dby
The Webster Bible,wbt
The Latin Vulgate,vul
Weymouth New Testament,wnt
1 New American Standard nas
2 American Standard Version asv
3 English Standard Version esv
4 New King James Version nkj
5 King James Version kjv
6 Holman Christian Standard Bible csb
7 Third Millennium Bible tmb
8 New International Version niv
9 New Living Translation nlt
10 New Revised Standard nrs
11 Revised Standard Version rsv
12 Good News Translation gnt
13 Douay-Rheims Bible rhe
14 The Message msg
15 The Complete Jewish Bible cjb
16 New Century Version ncv
17 GOD'S WORD Translation gwd
18 Hebrew Names Version hnv
19 World English Bible web
20 The Bible in Basic English bbe
21 Young's Literal Translation ylt
22 Today's New International Version tnv
23 New International Reader's Version nrv
24 The Darby Translation dby
25 The Webster Bible wbt
26 The Latin Vulgate vul
27 Weymouth New Testament wnt