Exemple #1
0
 def __init__(self, universe):
     self.Universe = universe
     
     #createResultObject = CreateResultObject()
     #self.ResultObject = createResultObject.getObject()
     
     self.Bituza = Bituza(self.Universe)
     self.booksDictOT = self.Bituza.booksDictOT()
     self.booksDictNT = self.Bituza.booksDictNT()
     
     self.SwordParser = SwordParser()
     
     self.history = History("sword_history", self.Universe.ConfigFiles)
     
     ConfigFile = Conf("./modules/sword/", "sword.conf")
     self.sword_module_name = ConfigFile.readVar("sword", "default_bible")
     self.language = ConfigFile.readVar("sword", "default_language")
     
     dir_path = ConfigFile.readVar("sword", "sword_directory")
     self.modules_path = dir_path + "/modules/texts/ztext"
     self.mods_d_path = dir_path + "/mods.d"
     
     self.ModsD = ModsD(self.mods_d_path)
Exemple #2
0
class Reader(object):
    def __init__(self, universe):
        self.Universe = universe
        
        #createResultObject = CreateResultObject()
        #self.ResultObject = createResultObject.getObject()
        
        self.Bituza = Bituza(self.Universe)
        self.booksDictOT = self.Bituza.booksDictOT()
        self.booksDictNT = self.Bituza.booksDictNT()
        
        self.SwordParser = SwordParser()
        
        self.history = History("sword_history", self.Universe.ConfigFiles)
        
        ConfigFile = Conf("./modules/sword/", "sword.conf")
        self.sword_module_name = ConfigFile.readVar("sword", "default_bible")
        self.language = ConfigFile.readVar("sword", "default_language")
        
        dir_path = ConfigFile.readVar("sword", "sword_directory")
        self.modules_path = dir_path + "/modules/texts/ztext"
        self.mods_d_path = dir_path + "/mods.d"
        
        self.ModsD = ModsD(self.mods_d_path)
    
    def readBible(self, c, a):
        try:
            book = a[0]
            print "BOOK ", book
        except IndexError:
            self.ResultObject.Error.Message = "Bitte Buchname angeben"
            return self.ResultObject
        else:
            if book.isdigit():
                book_id = int(book)
            else:
                book_id = self.getBookID(book)
            if not book_id:
                self.ResultObject.Error.Message = "Buch nicht gefunden"
                return self.ResultObject
            
        try:
            chapter = a[1]
        except IndexError:
            #self.ResultObject.Error.Message = "Bitte Kapitel angeben"
            #return self.ResultObject
            chapter = 1
        
        try:
            verse = a[2]
            verse = verse.split("-")
        except:
            pass
            "EXAMPLE: 1mose 1"
            #self.history.historyWrite(book + " " + chapter)
            return self.readWholeChapter(book_id, chapter)
        else:
            if len(verse) == 1:
                "EXAMPLE: 1mose 1 2"
                return self.readOneVerse(book_id, chapter, verse[0])
            elif len(verse) == 2:
                "EXAMPLE: 1mose 1 2-4"
                return self.readVerseRange(book_id, chapter, verse)
            
    def readOneVerse(self, book_number, chapter, verse):
        book_names = self.bookNamesDict()
        print "BOOK NUMBER", book_number
        if book_number:
            book_name = book_names[int(book_number)]
        else:
            self.ResultObject.Error.Message = "Buch nicht gefunden"
            return self.ResultObject
        
        module = ZModule(self.sword_module_name, self.modules_path)
        try:
            try:
                result = module.text_for_ref(book_name, chapter, verse)
            except ValueError:
                "EXAMPLE: 1mose 1-4"
                self.ResultObject.Error.Message = "Bitte nur ein Kapitel angeben"
                return self.ResultObject
            except TypeError:
                self.ResultObject.Error.Message = "ausgewaehltes Bibelmodul nicht verfuegbar. Versuchen Sie es evtl. klein zu schreiben."
                return self.ResultObject
            
        except IndexError:
            self.ResultObject.Error.Message = "Kapitel existiert nicht"
            return self.ResultObject
        else:
            self.history.historyWrite(str(book_number) + " " + str(chapter) )
            
            "ensure correct character encoding"
            try:
                #print "sword -> result: ", result
                result = result.decode("utf8")
            except:
                result = result.decode("iso-8859-1")
            
            try:
                bible_text, title_text, note_text = self.SwordParser.feed(result)
            except Exception, e:
                print "ERROR WHILE PARSING: ", e
            
            metaData = MetaData()
            metaData.Language = self.language
            
            #self.ResultObject.Payload.String = bible_text
            #self.ResultObject.Description.MetaData = metaData
            #return self.ResultObject
            return bible_text