Example #1
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
Example #2
0
    def structure(self, c, args):
        if len(args) == 0:
            query = """SELECT book_id, book_string, name_intern, chapter
            FROM structure
            JOIN books ON structure.book_id=books.id
            GROUP BY book_id"""
            head = ['book_id', 'book_string', 'name_intern', 'chapter']
        else:
            query = """SELECT book_id, book_string, name_intern, chapter, COUNT(*) AS number_verses
            FROM structure
            JOIN books ON structure.book_id=books.id
            WHERE name_intern = "{0}"
            GROUP BY chapter""".format(args[0])
            head = [
                'book_id', 'book_string', 'name_intern', 'chapter',
                'number_verses'
            ]

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

        result_object = Result()
        result_object.category = 'table'
        result_object.payload = result
        result_object.header = head
        return result_object
Example #3
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
Example #4
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
Example #5
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
Example #6
0
    def chord(self, c, args):
        from modules.frets.chords import Chords

        chords = Chords()
        result = chords.getAkkorde('dur')
        print(result)

        result_object = Result()
        result_object.category = "table"
        result_object.payload = result
        result_object.header = ['grundton', 'terz', 'quinte']
        return result_object
Example #7
0
    def capo(self, c, args):
        scale = [
            "c", "cis", "d", "dis", "e", "f", "fis", "g", "gis", "a", "ais",
            "b"
        ]
        result = self.frets("frets", scale[::-1])

        if len(args) == 0:
            #result.Payload.TableColorVertical = None
            return result
        else:
            if not args[0].isdigit():
                result_object = Result()
                result_object.error = 'invalid parameter: parameter has to be a number!'
                return result_object

            args = args[::-1]
            args.append("0")
            args = args[::-1]

            table = result.payload
            head = result.header

            table_new = []
            row_new = []
            head_new = []

            for fret in args:
                head_new.append(fret)

                for row_num, row in enumerate(table):

                    #for item in row:
                    #    row_new.append(item[5])
                    row_new.append(row[int(fret)])

                    if len(table_new) < len(scale):
                        table_new.append(row_new)
                    else:
                        row_a = table_new[row_num]
                        row_a.append(row[int(fret)])

                    row_new = []

            #self.ResultObject.Payload.Table = table_new
            #self.ResultObject.Payload.TableHeader = head_new
            #self.ResultObject.Payload.TableColorVertical = None
            #return self.ResultObject
            result_object = Result()
            result_object.category = "table"
            result_object.payload = table_new
            result_object.header = head_new
            return result_object
Example #8
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
Example #9
0
File: deck.py Project: nano13/tambi
    def toString(self, c, args):
        result_object = Result()

        try:
            deckname = args[0]
        except IndexError:
            result_object.error = 'please specify the deck by name!'
        else:
            deckpath = self.config.readPath("vocable", "deckpath")
            db_path = os.path.join(deckpath, deckname, 'database.sqlite')
            print(db_path)
            self.dbAdapter.initialize(db_path)
            result, header = self.dbAdapter.summary()

            result_object.category = "text"
            result_object.payload = result
            result_object.header = header

        return result_object
Example #10
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
Example #11
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)
Example #12
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
Example #13
0
File: deck.py Project: nano13/tambi
    def chronological(self, c, args):
        try:
            deck_prefix = args[0]
        except IndexError:
            deck_prefix = ''

        deckpath = self.config.readPath("vocable", "deckpath")
        root, dirs, path = next(iter(os.walk(deckpath)))

        entries_list = []
        for directory in dirs:
            if directory.startswith(deck_prefix):
                db_path = os.path.join(root, directory, "database.sqlite")
                self.dbAdapter.initialize(db_path)
                result = self.dbAdapter.selectDeckItems()

                for entry in result:
                    print(entry)
                    created = entry["created"]
                    if created:
                        created = datetime.datetime.fromtimestamp(
                            int(created)).strftime('%Y-%m-%d %H:%M:%S')
                    else:
                        created = datetime.datetime.fromtimestamp(0).strftime(
                            '%Y-%m-%d %H:%M:%S')
                    entries_list.append([
                        created, entry["name"], entry["word"],
                        entry["phonetical"], entry["translation"], directory
                    ])
        entries_list.sort()

        header = [
            'date', 'name', 'word', 'phonetical', 'translation', 'deck_name'
        ]

        result_object = Result()
        result_object.category = "table"
        result_object.payload = entries_list
        result_object.header = header
        return result_object
Example #14
0
File: deck.py Project: nano13/tambi
    def generateIPATable(self, command, args):
        if command == 'deck.ipaVowels':
            table_type = 'vowels'
        elif command == 'deck.ipaConsonants':
            table_type = 'consonants'
        try:
            deck_prefix = args[0]
        except IndexError:
            """ everything is fine, we just do not have an argument """
            deck_prefix = ''

        deckpath = self.config.readPath("vocable", "deckpath")
        root, dirs, path = next(iter(os.walk(deckpath)))
        dirs.sort()
        """ append all 'phonetical'-characters from all decks to the variable 'result_char_list' and pass it to the ipa-class to generate the table """
        result_char_list = []
        for directory in dirs:
            if directory.startswith(deck_prefix):
                db_path = os.path.join(root, directory, "database.sqlite")
                self.dbAdapter.initialize(db_path)
                result = self.dbAdapter.selectDeckItems()

                for entry in result:
                    phonetical = entry["phonetical"]
                    if phonetical:
                        for char in phonetical:
                            result_char_list.append(char)

        ipa = Ipa()
        result_table, header, header_vertical = ipa._generateIpaTableFromData(
            table_type, result_char_list)

        result_object = Result()
        result_object.category = "table"
        result_object.payload = result_table
        result_object.header = header
        result_object.header_left = header_vertical
        return result_object
Example #15
0
File: ipa.py Project: nano13/tambi
    def generateRawIpaTable(self, command, a):
        if command == 'ipa.vowels':
            phones = self.__getVowelsDict()
            result_table, header, header_vertical = self.__getVowelsRawTable()
        elif command == 'ipa.consonants':
            phones = self.__getConsonantsDict()
            result_table, header, header_vertical = self.__getConsonantsRawTable(
            )

        keys = phones.keys()
        for key in keys:
            position = phones[key]
            try:
                result_table[position[0]][position[1]] = key
            except IndexError:
                pass

        result_object = Result()
        result_object.category = "table"
        result_object.payload = result_table
        result_object.header = header
        result_object.header_left = header_vertical
        return result_object
Example #16
0
    def structure(self, c, args):
        self.initDbConnection()

        if len(args) == 0:
            query = """
            SELECT COUNT(*)
            FROM quran
            GROUP BY surah
            """
            header = ['verses_count']
            self.cursor.execute(query)

        elif len(args) == 1:
            query = """
            SELECT surah, COUNT(*)
            FROM quran
            WHERE surah=?
            """
            header = ['surah', 'verses_count']
            self.cursor.execute(query, [int(args[0])])

        else:
            query = """
            SELECT surah, ayah, word_count
            FROM quran
            WHERE surah=? AND ayah=?
            """
            header = ['surah', 'ayah', 'word_count']
            self.cursor.execute(query, [int(args[0]), int(args[1])])

        result = self.cursor.fetchall()

        result_object = Result()
        result_object.category = 'table'
        result_object.payload = result
        result_object.header = header
        return result_object
Example #17
0
File: deck.py Project: nano13/tambi
    def search(self, c, args):
        deckpath = self.config.readPath("vocable", "deckpath")
        root, dirs, path = next(iter(os.walk(deckpath)))
        dirs.sort()

        result_list = []
        result_header = ["deckname"]
        for directory in dirs:
            db_path = os.path.join(root, directory, "database.sqlite")
            self.dbAdapter.initialize(db_path)

            result = self.dbAdapter.search(args[0])

            if result:
                try:
                    result = result[0]
                except KeyError:
                    pass
                else:
                    result_line = []
                    result_line.append(directory)
                    for key in result.keys():
                        result_line.append(result[key])

                        result_header.append(key)

                    result_list.append(result_line)

            self.dbAdapter.closeDB()

        result_object = Result()
        result_object.category = "multimedia_table"
        #result_object.category = "table"
        result_object.payload = result_list
        result_object.header = result_header
        return result_object
Example #18
0
    def frets(self, c, args):
        if len(args) == 0:
            result_object = Result()
            result_object.error = 'please specify the tuning!'
            return result_object

        scale = [
            "c", "cis", "d", "dis", "e", "f", "fis", "g", "gis", "a", "ais",
            "b"
        ]
        head = "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"
        color = [[160, 160, 160], [255, 255, 255], [255, 255, 255],
                 [200, 200, 200], [255, 255, 255], [200, 200, 200],
                 [255, 255, 255], [200, 200, 200], [255, 255, 255],
                 [200, 200, 200], [255, 255, 255], [255, 255, 255],
                 [200, 200, 200]]

        # german_notaion: use "h" instead of "b"
        german_notation = False
        for item in args:
            if item == "h":
                german_notation = True

        result_table = []
        for item in args:
            if item == "h":
                item = "b"

            item = item.lower()

            result_line = []
            for i in range(13):
                result_line.append(item)

                try:
                    item_index = scale.index(item)
                except ValueError:
                    result_object = Result()
                    result_object.error = 'the specified tone \'' + item + '\' could not be recognized.'
                    return result_object
                    #self.ResultObject.Error.Message = "Fehler: Ton " +item+ " konnte nicht erkannt werden. (Es werden nur die Kreuztonarten erkannt)"
                    #return self.ResultObject

                # the successor:
                try:
                    item = scale[item_index + 1]
                except IndexError:
                    item = scale[item_index + 1 - 12]

            if german_notation:
                result_line = ["h" if x == "b" else x for x in result_line]

            result_table.append(result_line)

        #self.ResultObject.Payload.Table = result_table[::-1]
        #self.ResultObject.Payload.TableHeader = head
        #self.ResultObject.Payload.TableColorVertical = color
        print(head)
        result_object = Result()
        result_object.category = 'table'
        result_object.payload = result_table[::-1]
        result_object.header = head
        return result_object
Example #19
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