Beispiel #1
0
        def insert_in_db(tb, chapter, tr):
            versCount = 0
            for vers in chapter.findall("VERS"):
                versCount += 1

                # Does this vers and chapter already exist?
                v = BibleVers.objects.filter(bookNr=tb,
                                             chapterNr=chapter.get('cnumber'),
                                             versNr=vers.get('vnumber'))
                if v.count() <= 0:
                    v = BibleVers(bookNr=tb,
                                  chapterNr=chapter.get('cnumber'),
                                  versNr=vers.get('vnumber'))
                    v.save()
                else:
                    v = v[0]

                # Insert text if it does not already exist
                dbVers = BibleText.objects.filter(translationIdentifier=tr,
                                                  vers=v)
                if dbVers.count() <= 0:
                    dbVers = BibleText(translationIdentifier=tr,
                                       vers=v,
                                       versText=self.element_to_string(vers))
                    dbVers.save()

            return versCount
Beispiel #2
0
        def __insert(translation, book, chapter, vers, text):
            '''
                Insert the bible text into the database. Create the BibleVers
                and the BibleText if it does not exist.
                    @translation is a BibleTranslation instance
                    @book is a BibleBook instance
                    @chapter and @vers are integers
                    @text is a string
            '''

            # vnumber can contain multiple verses. In NGUE it is seperated by a 8209 (e.g. 16-17 is defined
            # as 16820917. So we have to check if this is the case, then separate the verse numbers, insert the
            # first one and every following as an empty verse.
            numverses = 1
            if str(vers).__contains__('8209'):
                vers, lastvers = int(str(vers).split('8209')[0]), int(
                    str(vers).split('8209')[1])
                numverses = lastvers - vers + 1

            # Does this vers already exist?
            v = BibleVers.objects.filter(bookNr=book,
                                         chapterNr=chapter,
                                         versNr=vers)
            if v.count() <= 0:
                v = BibleVers(bookNr=book, chapterNr=chapter, versNr=vers)
                v.save()
            else:
                v = v[0]

            # Insert text if it does not already exist
            t = BibleText.objects.filter(vers=v,
                                         translationIdentifier=translation)
            if t.count() <= 0:
                t = BibleText(vers=v,
                              translationIdentifier=translation,
                              versText=text)
                t.save()

                if numverses > 1:
                    for i in range(1, numverses):
                        __insert(translation, book, chapter, vers + i, '')
Beispiel #3
0
    def __insert(self, translation, book, chapter, vers, text):
        '''
            Insert the bible text into the database. Create the BibleVers
            and the BibleText if it does not exist.
                @translation is a BibleTranslation instance
                @book is a BibleBook instance
                @chapter and @vers are integers
                @text is a string
        '''


        # vnumber can contain multiple verses. In NGUE it is seperated by a 8209 (e.g. 16-17 is defined
        # as 16820917. So we have to check if this is the case, then separate the verse numbers, insert the
        # first one and every following as an empty verse.
        numverses = 1
        if str(vers).__contains__('8209'):
            vers, lastvers = int(str(vers).split('8209')[0]), int(str(vers).split('8209')[1])
            numverses = lastvers - vers + 1

        # Does this vers already exist?
        v = BibleVers.objects.filter(bookNr=book, chapterNr=chapter, versNr=vers)
        if v.count() <= 0:
            v = BibleVers(bookNr=book, chapterNr=chapter, versNr=vers)
            v.save()
        else:
            v = v[0]

        # Insert text if it does not already exist
        t = BibleText.objects.filter(vers=v, translationIdentifier=translation)
        if t.count() <= 0:
            t = BibleText(vers=v, translationIdentifier=translation, versText=text)
            t.save()

            if numverses > 1:
                for i in range(1, numverses):
                    __insert(translation, book, chapter, vers+i, '')
Beispiel #4
0
    def insert_bible_vers(self):
        self.stdout.write('Start parsing ...')

        ####################################################
        # Insert book names if they does not exist

        if not path.exists('bibles/osis.NGU.xml'):
          FILES = ['./bibles/GER_ILGRDE.xml', './bibles/GRC_GNTTR_TEXTUS_RECEPTUS_NT.xml', './bibles/GER_LUTH1912.xml', './bibles/GER_ELB1905_STRONG.xml', './bibles/GER_SCH1951_STRONG.xml']
        else:
          FILES = ['./bibles/GER_ELB1905_STRONG.xml', './bibles/GER_LUTH1912.xml', './bibles/GER_ILGRDE.xml', './bibles/GRC_GNTTR_TEXTUS_RECEPTUS_NT.xml']
        # FILE = './GER_SCH1951_STRONG.xml'
        # FILE = './GER_ELB1905_STRONG.xml'
        # FILE = './GER_LUTH1912.xml'
        # FILE = './GER_ILGRDE.xml'
        # FILE = './GER_SCH2000.xml'
        # FILE = './GRC_GNTTR_TEXTUS_RECEPTUS_NT.xml'

        for FILE in FILES:
            ####################################################
            # Insert bibles from zefanja xml
            baum = ElementTree.parse(FILE)
            root = baum.getroot()
            identifier = root.findtext('INFORMATION/identifier')
            language = root.findtext('INFORMATION/language')
            title = root.findtext('INFORMATION/title')

            self.stdout.write(identifier + ':')

            # Ask if this translation does already exist
            tr = BibleTranslation.objects.filter(identifier=identifier)
            # self.stdout.write('1')
            if tr.count() <= 0:
                # self.stdout.write('2')
                tr = BibleTranslation(identifier=identifier, name=title, language=language)
                # self.stdout.write('3')
                tr.save()
                # self.stdout.write('4')
                self.stdout.write(' -> created new translation ' + identifier + '.')
                # self.stdout.write('5')
            else:
                # self.stdout.write('-2')
                tr = tr[0]
            # self.stdout.write('6')

            # Insert verses
            for book in root.findall('BIBLEBOOK'):
                # self.stdout.write('a')
                chapterCount = 0

                # Does this book already exist
                # self.stdout.write('b')
                tb = BibleBook.objects.filter(nr=book.get('bnumber'))
                # self.stdout.write('c')
                if tb.count() <= 0:
                    # self.stdout.write('d')
                    tb = BibleBook(nr=int(book.get('bnumber')), name='', alternativeNames='')
                    # self.stdout.write('e')
                    tb.save()
                else:
                    # self.stdout.write('-d')
                    tb = tb[0]
                # self.stdout.write('f')

                versCount = 0
                # self.stdout.write('g')
                for chapter in book.findall('CHAPTER'):
                    chapterCount += 1
                    for vers in chapter.findall("VERS"):
                        versCount += 1

                        # Does this vers and chapter already exist?
                        v = BibleVers.objects.filter(bookNr=tb, chapterNr=chapter.get('cnumber'), versNr=vers.get('vnumber'))
                        if v.count() <= 0:
                            v = BibleVers(bookNr=tb, chapterNr=chapter.get('cnumber'), versNr=vers.get('vnumber'))
                            v.save()
                        else:
                            v = v[0]

                        # Insert text if it does not already exist
                        dbVers = BibleText.objects.filter(translationIdentifier=tr, vers=v)
                        if dbVers.count() <= 0:
                            dbVers = BibleText(translationIdentifier=tr, vers=v, versText=self.element_to_string(vers))
                            dbVers.save()
                self.stdout.write(' -> inserted book nr ' + book.get('bnumber') + ' with ' + str(chapterCount)  + ' chapters and ' + str(versCount) + ' verses.')
        self.stdout.write('done parsing!')