def setCurrentModule(self, c, args): self.current_module = args[0] result_object = Result() result_object.category = "list" result_object.payload = 'sword bible-module set to: ' + args[0] return result_object
def logs(self, c, a): base, dirs, files = next(iter(os.walk(self.logpath))) result_object = Result() result_object.category = "list" result_object.payload = sorted(files) return result_object
def count(self, c, args): result_object = Result() deck_prefix = None try: deck_prefix = args[0] except IndexError: """ everything is fine, we just do not have an argument """ pass deckpath = self.config.readPath("vocable", "deckpath") root, dirs, path = next(iter(os.walk(deckpath))) dirs.sort() counter = 0 for directory in dirs: try: if directory.startswith(deck_prefix): db_path = os.path.join(root, directory, "database.sqlite") self.dbAdapter.initialize(db_path) result = self.dbAdapter.count() counter += int(result) except TypeError: db_path = os.path.join(root, directory, "database.sqlite") self.dbAdapter.initialize(db_path) result = self.dbAdapter.count() counter += int(result) result_object.category = "string" result_object.payload = str(counter) return result_object
def textusReceptus(self, c, a): query = "SELECT verse, unicode FROM word NATURAL JOIN structure WHERE book_id=66 AND chapter=1 AND verse>=1 AND verse<=4" self.initDbConnection() self.cursor.execute(query) result = self.cursor.fetchall() current_verse_number = int(result[0][0]) #print(current_verse_number) result_list = [] result_line = "" j = 1 for i in range(len(result)): #print(current_verse_number)#, result_line if result[i][0] == current_verse_number: result_line += result[i][1] + " " else: j += 1 current_verse = int(result[j][0]) result_list.append(result_line) #print(i, current_verse_number) result_line = result[i][1] + " " result_object = Result() result_object.category = 'list' result_object.payload = result_list return result_object
def listModules(self, c, args): modules = SwordModules() result = [] try: found_modules = modules.parse_modules() except FileNotFoundError: category = 'list' else: for key in found_modules: row = [] row.append(key) #for item in found_modules[key]: # row.append(found_modules[key][item]) row.append(found_modules[key]['lang']) row.append(found_modules[key]['about'].replace('\par', "\n")) row.append(found_modules[key]['version']) if len(args) == 1: category = "itemized" if found_modules[key]['lang'] == args[0]: result.append(row) else: category = "table" result.append(row) result_object = Result() result_object.category = category result_object.payload = sorted(result) return result_object
def showHeightmap(self, c, args): lat_min = float(args[0]) lat_max = float(args[1]) lon_min = float(args[2]) lon_max = float(args[3]) delta_lat = vincenty([lat_min, lon_min], [lat_max, lon_min]).kilometers delta_lon = vincenty([lat_min, lon_min], [lat_min, lon_max]).kilometers print(delta_lat, delta_lon) import srtm geo_elevation_data = srtm.get_data() width = 1000 height = (delta_lon * width) / delta_lat print(width, height) #image = geo_elevation_data.get_image((1000, 1000), (50, 51), (8, 9), 800) image = geo_elevation_data.get_image((round(width), round(height)), (lat_min, lat_max), (lon_min, lon_max), int(args[4])) result_object = Result() result_object.category = "image" result_object.payload = image return result_object
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
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
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
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
def stop_log(self, c, a): self.terminate_log_thread = True self.log_thread_running = False result_object = Result() result_object.category = "text" result_object.payload = "gps logging stopped" return result_object
def listCanons(self, c, a): canons = pysword_canons.canons result = [] for key, value in canons.items(): result.append(key) result_object = Result() result_object.category = 'list' result_object.payload = result return result_object
def history(self, c, args): history = History("history_sword") if len(args) < 1: result = history.historyReadAll() else: result = history.historyReadAllWithFilter(args[0]) result_object = Result() result_object.payload = result[::-1] result_object.category = "list" return result_object
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
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
def fonts(self, c, args): filter_str = None if len(args) > 0: filter_str = str(args[0]) fonts = UnicodeFonts() available_fonts = fonts.printFonts(filter_str) result_object = Result() result_object.category = 'list' result_object.payload = available_fonts return result_object
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
def tableOfContents(self, c, a): base, dirs, files = next(iter(os.walk(MODULE_PATH))) result = [] for f in files: splitted = f.split('.') if splitted[1] == 'md': result.append(splitted[0]) result_object = Result() result_object.category = 'list' result_object.payload = sorted(result) return result_object
def modules(self, c, a): base, dirs, files = next(iter(os.walk('./modules'))) dirs.sort() try: dirs.remove('__pycache__') except ValueError: # if __pycache__ does not exists, we do not have do do here anything pass result_object = Result() result_object.category = "list" result_object.payload = dirs return result_object
def start_log(self, c, a): log_db_name = str(time.time()).split('.')[0] + ".sqlite" result_object = Result() if not self.log_thread_running: self.terminate_log_thread = False self.logging_thread = _thread.start_new_thread( self.__loggingThread, (log_db_name, )) result_object.payload = "gps logging started" else: result_object.payload = "gps logging already running" result_object.category = "text" return result_object
def position(self, c, a): result_object = Result() try: data = self.getPosition() except NoFixError: result_object.category = "text" result_object.payload = "no gps fix available" else: if data: result_object.category = "table" result_object.payload = [ ['Latitude', data['latitude']], ['Longitude', data['longitude']], ['Altitude', data['altitude']], ['Speed', data['speed']], ['Track', data['track']], ['Climb', data['climb']], ['Time', data['time']], ['Error Horizontal', data['error_horizontal']], ['Error Vertical', data['error_vertical']], ] else: result_object.category = "text" result_object.payload = 'could not find any working position provider (like gpsd or geoclue)' return result_object
def commands(self, none1, none2): dic = self.getCommands() commands = sorted(dic.items()) all_commands = [] for key in commands: line = str(key).split(",")[0] all_commands.append(str(line[2:-1])) result_object = Result() result_object.category = "list" result_object.payload = all_commands return result_object
def showMap(self, c, args, queue): """ import time for i in range(10): queue.put(str(i)) print("putted:", i) time.sleep(1) """ result_object = Result() result_object.category = "command" result_object.payload = { "command": "qmapview", "args": args, } return result_object
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
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
def books(self, c, args): structure = BibleStructure(self.canon) books = structure.get_books() result = [] if ((not len(args) == 0) and (args[0] == 'ot')) or (len(args) == 0): for book in books['ot']: formatted = str(book)[5:][:-1] result.append(formatted) if ((not len(args) == 0) and (args[0] == 'nt')) or (len(args) == 0): for book in books['nt']: formatted = str(book)[5:][:-1] result.append(formatted) result_object = Result() result_object.category = "list" result_object.payload = result return result_object
def showDependencies(self, c, args): result = [] for key in sys.modules.keys(): result.append(key) result = sorted(result) if len(args) > 0 and args[0] == 'compact': result = [x for x in result if "." not in x] """ kick out the imported parts of this programm itself from the result """ base, dirs, files = next(iter(os.walk('./'))) for folder in dirs: result = [x for x in result if folder not in x] result_object = Result() result_object.category = 'list' result_object.payload = result return result_object
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
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)
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