Exemple #1
0
    def search(self, c, args):
        result_object = Result()

        try:
            key = '%' + args[0] + '%'
        except IndexError:
            result_object.error = 'ERROR: you have to specify a search pattern'

        else:
            query = """SELECT surah, ayah, arabic, transcription, de_DE
            FROM quran
            WHERE arabic LIKE ? OR transcription LIKE ? OR de_DE LIKE ?"""
            self.initDbConnection()
            self.cursor.execute(query, [key, key, key])

            result = self.cursor.fetchall()

            result_object.category = "itemized"
            result_object.payload = result
            result_object.header = [
                'surah', 'ayah', 'arabic', 'transcription', 'de_DE'
            ]
            result_object.name = "quran_search"

        return result_object
Exemple #2
0
    def wordHelper(self, args, header):
        self.initDbConnection()

        columns = ", ".join(header)
        if len(args) == 1:
            query = "SELECT {0} FROM quran WHERE surah=?".format(columns)
            self.cursor.execute(query, [int(args[0])])

        elif len(args) == 2:
            if args[1].find('-') == -1:
                query = "SELECT {0} FROM quran WHERE surah=? AND ayah=?".format(
                    columns)
                self.cursor.execute(query, [int(args[0]), int(args[1])])

            else:
                ayah_min, ayah_max = args[1].split('-')
                query = "SELECT {0} FROM quran WHERE surah=? AND ayah>=? AND ayah<=?".format(
                    columns)
                self.cursor.execute(
                    query,
                    [int(args[0]), int(ayah_min),
                     int(ayah_max)])

        result = self.cursor.fetchall()

        result_object = Result()
        result_object.category = "itemized"
        result_object.payload = result
        result_object.header = header
        result_object.name = "quran_word"
        return result_object
Exemple #3
0
    def order(self, c, args):
        order = [
            96, 68, 73, 74, 1, 111, 81, 87, 92, 89, 93, 94, 103, 100, 108, 102,
            107, 109, 105, 113, 114, 112, 53, 80, 97, 91, 85, 95, 106, 101, 75,
            104, 77, 50, 90, 86, 54, 38, 7, 72, 36, 25, 35, 19, 20, 56, 26, 27,
            28, 17, 10, 11, 12, 15, 6, 37, 31, 34, 39, 40, 41, 42, 43, 44, 45,
            46, 51, 88, 18, 16, 71, 14, 21, 23, 32, 52, 67, 69, 70, 78, 79, 82,
            84, 30, 29, 83, 2, 8, 3, 33, 60, 4, 99, 57, 47, 13, 55, 76, 65, 98,
            59, 24, 22, 63, 58, 49, 66, 64, 61, 62, 48, 5, 9, 110
        ]
        result = []
        for item in order:
            result.append(str(item))

        if args:
            try:
                index = result.index(str(args[0]))
            except ValueError:
                pass
            else:
                if index == 0:
                    result = result[:2]
                elif index == 113:
                    result = result[-2:]
                else:
                    result = result[index - 1:index + 2]

        result_object = Result()
        result_object.category = "list"
        result_object.payload = result
        result_object.header = ""
        result_object.name = "quran_order"
        return result_object
Exemple #4
0
    def books(self, c, a):
        query = "SELECT name_intern FROM books"
        self.initDbConnection()
        self.cursor.execute(query)
        result = self.cursor.fetchall()

        result_object = Result()
        result_object.category = "table"
        result_object.header = ["name_intern"]
        result_object.payload = result
        result_object.name = "bituza.books"
        return result_object
Exemple #5
0
    def stats(self, c, a):
        dictOT = self.booksDictOT()
        dictAT = self.booksDictNT()

        try:
            book_id = dictOT[a[0]]
        except:
            try:
                book_id = dictAT[a[0]]
            except:
                result = Result()
                result.error = "FEHLER: bitte Buch angeben!"
                return result
        try:
            chapter = a[1]
        except:
            result = Result()
            result.error = "FEHLER: bitte Kapitel angeben!"
            return result

        query_head = "SELECT book_string, chapter, verse, stats_verse, total_v, total_k, total_b, sum_v, sum_k, sum_b FROM stats NATURAL JOIN structure "

        if len(a) == 2:
            query_tail = "WHERE book_id=? AND chapter=?"
            values = book_id, chapter
        elif len(a) == 3:
            if a[2].find("-") > -1:
                start_verse, end_verse = a[2].split("-")
                query_tail = "WHERE book_id=? AND chapter=? AND verse>=? AND verse<=?"
                values = book_id, chapter, start_verse, end_verse
            else:
                query_tail = "WHERE book_id=? AND chapter=? AND verse=?"
                verse = a[2]
                values = book_id, chapter, verse

        query = query_head + query_tail

        self.initDbConnection()
        self.cursor.execute(query, values)
        result = self.cursor.fetchall()

        head = "buch", "kapitel", "vers", "stats_verse", "total_v", "total_k", "total_b", "sum_v", "sum_k", "sum_b"
        metaLang = "de", "de", "de", "de", "de", "de", "de", "de", "de", "de"
        name = "stats"

        result_object = Result()
        result_object.category = "table"
        result_object.header = head
        result_object.payload = result
        result_object.metaload = metaLang
        result_object.name = name
        return result_object
Exemple #6
0
    def height_diagram(self, c, args):
        result_object = Result()

        filename = self.__determineFilename(args)
        if not filename:
            result_object.error = 'a file matching to the specified one could not be found'
            return result_object

        filepath = os.path.join(self.logpath, filename)
        dbAdapter = DbAdapter(filepath)
        data = dbAdapter.selectDiagramData()

        result_object.category = "diagram"
        result_object.payload = data
        result_object.name = filename
        return result_object
Exemple #7
0
    def searchBookRange(self, command, start_book, end_book, search_pattern):
        book_list = self.getBookList()
        try:
            book_start_index = book_list.index(start_book)
        except:
            result = Result()
            result.error = "FEHLER: Buch " + unicode(
                start_book) + " konnte nicht gefunden werden!"
            return result
        try:
            book_end_index = book_list.index(end_book)
        except:
            result = Result()
            result.error = "FEHLER: Buch " + unicode(
                end_book) + " konnte nicht gefunden werden!"
            return result

        result_list = []
        i = book_start_index - 1
        while i < book_end_index:
            i += 1

            search_book = book_list[i]

            result, head, metaLanguage = self.searchSingleBook(
                command, search_book, search_pattern, False)
            result_list.append(result)

        format_list = []
        for item in result_list:
            for item2 in item:
                format_list.append(item2)

        name = "search result: " + search_pattern

        result_object = Result()
        result_object.category = "table"
        result_object.header = head
        result_object.payload = format_list
        result_object.metaload = metaLanguage
        result_object.name = name
        return result_object
Exemple #8
0
    def dictionaryHelper(self, args, language):
        result_object = Result()

        query = """
        SELECT display, gloss
        FROM {0}
        WHERE display LIKE ? OR gloss LIKE ?
        """.format(language)
        try:
            param = '%' + str(args[0]) + '%'
        except IndexError:
            result_object.error = 'invalid parameter'
        else:
            self.initDbConnection()
            self.cursor.execute(query, [param, param])
            result_object.payload = self.cursor.fetchall()

        result_object.category = "itemized"
        result_object.name = "dictionary result"
        return result_object
Exemple #9
0
    def searchGlobal(self, c, head, metaLanguage, query_head, query_mid,
                     query_tail, search_pattern, result_in_table):
        if query_tail:
            query = query_head + query_mid + "?" + query_tail
        else:
            query = query_head + query_mid + "?"

        #print(query, result_in_table)

        if c == "bituza.search.elberfelder":
            value = ["%" + str(search_pattern) + "%"]
        elif c == "bituza.search.unicode":
            value = ["%" + str(search_pattern) + "%"]
        else:
            value = [str(search_pattern)]

        self.initDbConnection()
        self.cursor.execute(query, value)
        result = self.cursor.fetchall()
        #print(result)

        if len(result) == 0:
            if result_in_table:
                result = Result()
                result.error = "FEHLER: keine Ergebnisse gefunden!"
                return result
            else:
                return []
        else:
            if result_in_table:
                name = "suchergebnis: " + search_pattern
                result_object = Result()
                result_object.category = "table"
                result_object.header = head
                result_object.payload = result
                result_object.metaload = metaLanguage
                result_object.name = name
                return result_object

            else:
                return (result)
Exemple #10
0
    def sql(self, c, a):
        try:
            query = a[0]
        except:
            result = Result()
            result.error = "FEHLER: bitte SQL-Abfrage als Argument übergeben!"
            return result

        self.initDbConnection()
        self.cursor.execute(query)
        result = self.cursor.fetchall()

        head = "1"
        name = "tabelle: sql"

        result_object = Result()
        result_object.category = "table"
        result_object.header = head
        result_object.payload = result
        result_object.name = name
        return result_object
Exemple #11
0
    def word(self, c, a):
        #query_head = "SELECT book_string, chapter, verse, unicode, translation_de, transcription, tw, code, wv, wk, wb, abk, abb, abv, anz_b FROM word NATURAL JOIN structure WHERE book_id=? AND chapter=?"
        #head = "buch", "kapitel", "vers", "unicode", "elberfelder", "transcription", "tw", "code", "wv", "wk", "wb", "abk", "abb", "abv", "anz_b"

        query_head = "SELECT unicode, translation_de, transcription FROM word NATURAL JOIN structure WHERE book_id=? AND chapter=?"
        head = "unicode", "elberfelder", "transcription"

        dictOT = self.booksDictOT()
        dictNT = self.booksDictNT()
        testament = None

        try:
            book_id = dictOT[a[0]]
        except:
            try:
                book_id = dictNT[a[0]]
            except:
                result = Result()
                result.error = "FEHLER: bitte Buch angeben!"
                return result
            else:
                testament = "NEW"
                metaLanguage = "de", "de", "de", "gr", "de", "de", "de", "de", "de", "de", "de", "de", "de", "de", "de"
        else:
            testament = "OLD"
            metaLanguage = "de", "de", "de", "il", "de", "de", "de", "de", "de", "de", "de", "de", "de", "de", "de"

        if len(a) == 2:
            query = query_head
            if a[1].isdigit():
                values = book_id, a[1]
            else:
                result = Result()
                result.error = "FEHLER: bitte Kapitel als Zahl angeben!"
                return result
        elif len(a) == 3:
            query = query_head + " AND verse=?"
            if a[1].isdigit():
                if a[2].isdigit():
                    values = book_id, a[1], a[2]
                else:
                    try:
                        first, last = a[2].split("-")
                    except ValueError:
                        result_object = Result()
                        result_object.error = 'invalid input'
                        return result_object

                    query = query_head + " AND verse>=? AND verse<=?"
                    values = book_id, a[1], first, last
            else:
                result_object = Result()
                result_object.error = "FEHLER: bitte Kapitel als Zahl angeben!"
                return result_object
        else:
            result_object = Result()
            result_object.error = "FEHLER: bitte Kapitel als Zahl angeben!"
            return result_object

        self.initDbConnection()
        self.cursor.execute(query, values)
        result = self.cursor.fetchall()

        if len(result) == 0:
            result_object = Result()
            result_object.error = "FEHLER: diese Stelle existiert nicht!"
            return result
        else:
            name = ["tabelle: "]
            for i in range(len(a)):
                name.append(a[i])

            name = " ".join(name)

            result_object = Result()
            result_object.category = "table"
            result_object.payload = result
            result_object.metaload = metaLanguage
            result_object.header = head
            result_object.name = name
            return result_object