コード例 #1
0
ファイル: survival.py プロジェクト: nano13/tambi
 def read(self, c, args):
     if len(args) <= 0:
         result_object = Result()
         result_object.error = 'please specify the chapter you want to read. see for the command "survival.toc"'
         return result_object
     
     filepath = MODULE_PATH + os.sep + args[0]+".md"
     
     if not os.path.exists(filepath):
         result_object = Result()
         result_object.error = 'chapter '+args[0]+' not found'
         return result_object
     
     input_file = input_file = codecs.open(filepath, mode="r", encoding="utf-8")
     md_file = input_file.read()
     html = '<h1>'+args[0]+'</h1>'
     html += markdown.markdown(md_file, extensions=[
         'markdown.extensions.sane_lists',
         'markdown.extensions.nl2br',
         'markdown.extensions.extra',
         'markdown.extensions.tables',
     ])
     
     folderpath = '/modules/survival/guide/'.replace('/', os.sep)
     html = html.replace('src="', 'src="' + MODULE_PATH + os.sep)
     html = html.replace('<table>', '<table border="1">')
     
     #fobj = open("/tmp/mktest.html", "w")
     #fobj.write(html)
     #fobj.close()
     
     result_object = Result()
     result_object.category = "html"
     result_object.payload = html
     return result_object
コード例 #2
0
    def word(self, command, args):
        connection = sqlite3.connect(
            os.path.join(MODULE_PATH, 'TRi.bbl.mybible'))
        cursor = connection.cursor()

        try:
            book_id = self.booksDict(args[0])
        except:
            result_object = Result()
            result_object.error = 'ERROR: You have to specify a book! See command "bituza.books" for a list of the possible book names!'
            return result_object
        else:
            if len(args) == 1:
                result_object = Result()
                result_object.error = 'ERROR: You have to specify at least a chapter!'
                return result_object
            elif len(args) == 2:
                query = "SELECT Chapter, Verse, Scripture FROM Bible WHERE Book=? AND Chapter=?"
                cursor.execute(query, [book_id, args[1]])
            elif len(args) == 3:
                if args[2].find('-') == -1:
                    query = "SELECT Chapter, Verse, Scripture FROM Bible WHERE Book=? AND Chapter=? AND Verse=?"
                    cursor.execute(query, [book_id, args[1], args[2]])
                else:
                    verse_min, verse_max = args[2].split('-')
                    query = "SELECT Chapter, Verse, Scripture FROM Bible WHERE Book=? AND Chapter=? AND Verse>=? AND Verse<=?"
                    cursor.execute(query,
                                   [book_id, args[1], verse_min, verse_max])

            result = cursor.fetchall()

            if command == 'esword.word' or command == 'esword':
                payload = []
                for i, verse in enumerate(result):
                    payload.append(
                        [verse[0], verse[1],
                         self.parseText(verse[2])])
                category = 'text'
            elif command == 'esword.interlinear':
                payload = []
                for i, verse in enumerate(result):
                    parsed = self.parseInterlinear(result[i][2])
                    """ flatten the output:"""
                    for item in parsed:
                        """ to show the chapter, verse, greek, english ..."""
                        payload.append(
                            [result[i][0], result[i][1], item[0], item[1]])
                    #payload.append(parsed)
                category = 'table'

            result_object = Result()
            result_object.category = category
            result_object.payload = payload
            return result_object
コード例 #3
0
ファイル: bituza.py プロジェクト: nano13/tambi
    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
コード例 #4
0
ファイル: quran.py プロジェクト: nano13/tambi
    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
コード例 #5
0
ファイル: gps.py プロジェクト: nano13/tambi
    def plot(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)
        boundings = dbAdapter.selectMinMaxCoordinate()
        mapView = QMapView(boundings)

        data = dbAdapter.selectLatLon()
        points_list = []
        for pos in data:
            #mapView.addPoint(pos['longitude'], pos['latitude'])
            x, y = pos['latitude'], pos['longitude']
            points_list.append([x, y])
        mapView.addPointList(points_list)
        mapView.drawPointList()

        #mapView.scaleViewToContents()

        result_object.category = "qt_widget"
        result_object.payload = mapView
        return result_object
コード例 #6
0
ファイル: survival.py プロジェクト: nano13/tambi
 def search(self, c, args):
     try:
         pattern = args[0]
     except:
         result_object = Result()
         result_object.error = 'you have to specify a search-pattern'
         return result_object
     else:
         import fileinput, glob, string
         result = []
         for line in fileinput.input(glob.glob(MODULE_PATH + os.sep + '*.md')):
             
             num_matches = line.lower().count(pattern.lower())
             if num_matches:
                 filepath = fileinput.filename()
                 filename = filepath.replace(MODULE_PATH + os.sep, '').replace('.md', '')
                 if not filename in result:
                     result.append(filename)
                 else:
                     pass
                     # we could raise a counter here to show, how often the pattern was found in one module ...
         
         result_object = Result()
         result_object.category = 'list'
         result_object.payload = result
         return result_object
コード例 #7
0
ファイル: bituza.py プロジェクト: nano13/tambi
    def summary(self, c, args):
        result_object = Result()

        if len(args) == 0:
            result_object.error = "please specify a book. see bituza.books for the exact names"
            return result_object

        fobj = open("./modules/bituza/bible_summary/bible_summary.txt")

        lines_to_return = ""
        in_section = False
        for line in fobj:
            if line.find(args[0]) >= 0:
                in_section = True
                lines_to_return += line
            elif in_section and line.find("===") >= 0:
                in_section = False
            elif in_section:
                lines_to_return += line

        fobj.close()

        result_object.category = "text"
        result_object.payload = lines_to_return
        return result_object
コード例 #8
0
 def man(self, c, args):
     result_object = Result()
     
     try:
         args[0]
     except IndexError:
         result_object.payload = builtin_man_pages.module_description
     else:
         if args[0].find('.') == -1:
             module_name = args[0]
             command_name = 'module_description'
         else:
             splitted = args[0].split('.')
             command_name = ""
             for i, fragment in enumerate(splitted):
                 if i <= 0:
                     module_name = fragment
                 elif i > 0:
                     command_name += fragment + '_'
             command_name = command_name[:-1]
         
         import_query = "import modules."+module_name+".man as man"
         try:
             exec(import_query, globals())
         except ModuleNotFoundError:
             
             exec_result = "result"
             try:
                 exec(exec_result + " = builtin_man_pages."+args[0], globals())
             except AttributeError:
                 result_object.error = 'no man-page for this command or module found'
             else:
                 result_object.payload = args[0] +"\n"+result
         else:
             exec_result = "result"
             try:
                 exec(exec_result + " = man."+command_name, globals())
             except AttributeError:
                 result_object.error = 'no man page for this command'
             else:
                 result_object.payload = args[0] +"\n"+result
     
     result_object.category = 'text'
     return result_object
コード例 #9
0
ファイル: bituza.py プロジェクト: nano13/tambi
    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
コード例 #10
0
ファイル: sword.py プロジェクト: nano13/tambi
    def setCanon(self, c, args):
        result_object = Result()

        canons = self.listCanons(None, None)
        if len(args) > 0 and args[0] in canons.payload:
            self.canon = args[0]
            result_object.payload = 'canon changed to: ' + args[0]
        else:
            result_object.error = 'no canon specified or canon unknown'

        result_object.category = 'list'
        return result_object
コード例 #11
0
ファイル: frets.py プロジェクト: nano13/tambi
    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
コード例 #12
0
ファイル: bituza.py プロジェクト: nano13/tambi
    def search(self, command, args):
        #head = "buch", "kapitel", "vers", "unicode", "elberfelder", "ascii", "zahlencode", "tw", "wv", "wk", "wb", "abk", "abb", "abv", "anz_b"
        #query_head = "SELECT book_string, chapter, verse, unicode, translation_de, ascii, code, tw, wv, wk, wb, abk, abb, abv, anz_b FROM word NATURAL JOIN structure WHERE"

        if len(args) == 1:
            search_pattern = args[0]

            head, query_head, query_mid, metaLanguage = self.searchGetQueryMid(
                command)
            query_tail = None
            return self.searchGlobal(command, head, metaLanguage, query_head,
                                     query_mid, query_tail, search_pattern,
                                     True)

        elif len(args) == 3:
            if args[1] == "in":
                search_pattern = args[0]
                search_book = args[2]

                if search_book.find("-") > -1:
                    start_book, end_book = search_book.split("-")
                    return self.searchBookRange(command, start_book, end_book,
                                                search_pattern)
                else:
                    result, head, metaLanguage = self.searchSingleBook(
                        command, search_book, search_pattern, True)
                    return result
            else:
                result = Result()
                result.error = "FEHLER: suchanfrage konnte nicht sinnvoll verarbeitet werden!"
                return result

        else:
            result = Result()
            result.error = "FEHLER: suchanfrage konnte nicht sinnvoll verarbeitet werden!"
            return result
コード例 #13
0
ファイル: gps.py プロジェクト: nano13/tambi
    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
コード例 #14
0
ファイル: deck.py プロジェクト: 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
コード例 #15
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
コード例 #16
0
ファイル: bituza.py プロジェクト: nano13/tambi
    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)
コード例 #17
0
ファイル: bituza.py プロジェクト: nano13/tambi
    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
コード例 #18
0
ファイル: bituza.py プロジェクト: nano13/tambi
 def searchSingleBook(self, command, search_book, search_pattern,
                      result_in_table):
     dictOT = self.booksDictOT()
     dictNT = self.booksDictNT()
     try:
         book_id = dictOT[search_book]
     except:
         try:
             book_id = dictNT[search_book]
         except:
             result = Result()
             result.error = "FEHLER: bitte Buch angeben!"
             return result
     #else:
     head, query_head, query_mid, metaLanguage = self.searchGetQueryMid(
         command)
     query_tail = " AND book_id=" + str(book_id)
     result = self.searchGlobal(command, head, metaLanguage, query_head,
                                query_mid, query_tail, search_pattern,
                                result_in_table)
     return result, head, metaLanguage
コード例 #19
0
ファイル: sword.py プロジェクト: nano13/tambi
    def listLanguages(self, c, a):
        result_object = Result()

        result = []
        modules = SwordModules()
        try:
            found_modules = modules.parse_modules()
        except FileNotFoundError:
            result_object.category = "error"
            result_object.error = "no sword modules could be found!"
        else:
            for main_key in found_modules:
                language = found_modules[main_key]['lang']

                if not language in result:
                    result.append(language)

            result = sorted(result)
            result_object.category = "list"
            result_object.payload = result

        return result_object
コード例 #20
0
ファイル: bituza.py プロジェクト: nano13/tambi
    def elberfelder(self, c, args):
        result_object = Result()
        error = None
        result = None

        query = None

        if len(args) == 2:
            # select a whole chapter
            query = """SELECT chapter, verse, elberfelder_verse FROM elberfelder
            JOIN structure ON structure.structure_row_id = elberfelder.structure_row_id
            JOIN books ON structure.book_id = books.id
            WHERE books.name_intern=? AND structure.chapter=?"""
            params = [args[0], args[1]]
        elif len(args) == 3:
            query = """SELECT verse, elberfelder_verse FROM elberfelder
            JOIN structure ON structure.structure_row_id = elberfelder.structure_row_id
            JOIN books ON structure.book_id = books.id
            WHERE books.name_intern=? AND structure.chapter=? AND structure.verse >= ? AND structure.verse <= ?"""
            if args[2].find('-') >= 0:
                verse_start, verse_end = args[2].split('-')
                params = [args[0], args[1], verse_start, verse_end]
            else:
                params = [args[0], args[1], args[2], args[2]]
        else:
            error = 'command could not be understood'

        if query:
            self.initDbConnection()
            self.cursor.execute(query, params)
            result = self.cursor.fetchall()

        result_object.error = error
        result_object.category = 'list'
        result_object.payload = result
        return result_object
コード例 #21
0
ファイル: gps.py プロジェクト: nano13/tambi
    def stats(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)

        result_table = []

        dbAdapter = DbAdapter(filepath)

        distance = 0
        data = dbAdapter.selectLogData()
        last_pos = None
        for pos in data:
            if last_pos:
                vincenty_dist = vincenty([
                    last_pos['latitude'],
                    last_pos['longitude'],
                ], [
                    pos['latitude'],
                    pos['longitude'],
                ]).kilometers
                distance += vincenty_dist

            last_pos = pos

        result_table.append(['distance (path) [km]', round(distance, 2)])

        start_stop = dbAdapter.selectStartStopCoordinates()
        distance_air = vincenty(
            [start_stop['start_lat'], start_stop['start_lon']],
            [start_stop['stop_lat'], start_stop['stop_lon']]).kilometers
        result_table.append(['distance (air) [km]', round(distance_air, 2)])

        t_stats = dbAdapter.selectTimeStats()

        try:
            time_min = datetime.fromtimestamp(
                t_stats['time_min']).strftime("%d.%m.%Y %R")
            time_max = datetime.fromtimestamp(
                t_stats['time_max']).strftime("%d.%m.%Y %R")
        except TypeError:
            result_table.append(['time_start', 'n/a'])
            result_table.append(['time_end', 'n/a'])
        else:
            result_table.append(['time_start', time_min])
            result_table.append(['time_end', time_max])

        try:
            speed = round(
                distance /
                ((t_stats['time_max'] - t_stats['time_min']) / 60 / 60), 2)
        except TypeError:
            result_table.append(['speed [km/h]', 'n/a'])
        else:
            result_table.append(['speed [km/h]', speed])

        boundings = dbAdapter.selectMinMaxCoordinate()
        result_table.append(['lat_min', boundings['lat_min']])
        result_table.append(['lat_max', boundings['lat_max']])
        result_table.append(['lon_min', boundings['lon_min']])
        result_table.append(['lon_max', boundings['lon_max']])

        altitude_min_max = dbAdapter.selectMinMaxAltitude()
        result_table.append(['alt_min', altitude_min_max['alt_min']])
        result_table.append(['alt_max', altitude_min_max['alt_max']])

        speed = dbAdapter.selectSpeedStats()
        result_table.append(['speed_min', speed['speed_min']])
        result_table.append(['speed_max', speed['speed_max']])
        result_table.append(['speed_average', speed['speed_average']])

        count = dbAdapter.selectCount()
        result_table.append(['samples count', count['count']])

        result_object.category = "table"
        result_object.payload = result_table
        return result_object
コード例 #22
0
ファイル: bituza.py プロジェクト: nano13/tambi
    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
コード例 #23
0
ファイル: sword.py プロジェクト: nano13/tambi
    def word(self, command, args):
        result = None
        result_object = Result()

        modules = SwordModules()
        try:
            found_modules = modules.parse_modules()
        except FileNotFoundError:
            result_object.error = 'no sword modules found on this computer. please install some!'
        else:
            try:
                bible = modules.get_bible_from_module(self.current_module)

                try:
                    book = args[0]

                    import modules.sword.book_names.books_de as books_de
                    if book in books_de.books:
                        book = books_de.books[book]

                    if len(args) == 2:
                        result = bible.get(books=[book],
                                           chapters=[int(args[1])],
                                           clean=True,
                                           join='#|#')

                        splitted = result.split('#|#')
                        result = []
                        for i, line in enumerate(splitted):
                            result.append([i + 1, line.strip()])

                    elif args[2].find('-') > -1:
                        verse_min, verse_max = args[2].split('-')
                        verse_range = range(int(verse_min), int(verse_max) + 1)

                        try:
                            result = bible.get(books=[book],
                                               chapters=[int(args[1])],
                                               verses=verse_range,
                                               clean=True,
                                               join='#|#')
                        except IndexError:
                            result_object.error = 'invalid verse range'
                        else:
                            splitted = result.split('#|#')
                            result = []
                            for i, line in enumerate(splitted):
                                result.append(
                                    [i + int(verse_min),
                                     line.strip()])
                    else:
                        verse_range = int(args[2])

                        result = bible.get(books=[book],
                                           chapters=[int(args[1])],
                                           verses=verse_range,
                                           clean=True,
                                           join='\n')
                except ValueError as e:
                    result_object.error = str(e)
                except KeyError as e:
                    result_object.error = 'book not found in current bible: ' + str(
                        book) + "\n\n" + str(e)
                except IndexError as e:
                    result_object.error = 'invalid input. please have a look at the man-page' + "\n\n" + str(
                        e)
            except KeyError:
                result_object.error = 'current module does not exist: ' + self.current_module
            except ValueError as e:
                result_object.error = str(e)

        result_object.category = "text"
        if result:
            for item in args:
                command += ' ' + str(item)
            if type(result) == list:
                result.insert(0, command)
            elif type(result) == str:
                result = [result]
                result.insert(0, command)
            result_object.payload = result
        return result_object
コード例 #24
0
ファイル: frets.py プロジェクト: nano13/tambi
    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