def get_classes(self): results = [] con = dbapi2.connect(Infrastructure().get_db_path()) res = con.execute("Select module_name, class_name from commands where active='1' group by class_name") for r in res: results.append(r) return results
def lookup(self, command_name, limit): results = [] con = dbapi2.connect(Infrastructure().get_db_path()) phrases = command_name.split() if len(phrases) == 1: res = con.execute('SELECT class_name, entry_name, command_name\ from commands where command_name like "%'+phrases[0]+'%"\ ORDER BY command_name LIMIT '+str(limit)+'') elif len(phrases) == 2: res = con.execute('SELECT class_name, entry_name, command_name\ from commands where command_name like "%'+phrases[0]+'%" and command_name like "%'+phrases[1]+'%"\ ORDER BY command_name LIMIT '+str(limit)+'') elif len(phrases) > 2: res = con.execute('SELECT class_name, entry_name, command_name\ from commands where command_name like "%'+phrases[0]+'%"\ and command_name like "%'+phrases[1]+'%"\ and command_name like "%'+phrases[2]+'%"\ ORDER BY command_name LIMIT '+str(limit)+'') else: res = con.execute('SELECT class_name, entry_name, command_name\ from commands\ ORDER BY command_name LIMIT '+str(limit)+'') for r in res: results.append(r) return results
def __init__(self): if not Infrastructure().db_file_exists(): Infrastructure().build_path() self.build_default_db() self.gui = AssistantGUI() self.gui.set_empty_title("[enter command]") self.gui.hide() self.executor = Executor() self.executor.set_content_listener(self.content_changed) self.executor.set_command_listener(self.command_changed) self.executor.start() self.visible = False self.lastKeyPressed = "left ctrl" self.lastPressedTime = time.time() self.updateContent(self.executor.get_commands()) self.showTriggerLastTime = 0.0
def reinit(self): con = dbapi2.connect(Infrastructure().get_db_path()) con.execute("DROP TABLE IF EXISTS commands") con.execute("CREATE TABLE commands (\ id INTEGER PRIMARY KEY, \ module_name TEXT,\ class_name TEXT,\ entry_name TEXT,\ command_name TEXT UNIQUE,\ active INTEGER)")
def closest(lat, lon, n_samples): df = Infrastructure.get_instance().get_all_data().copy() df["distance"] = df.apply( lambda row: haversine_distance(lat, lon, row["lat"], row["lon"]), axis=1 ) df.sort_values("distance", inplace=True) return df.groupby("type").head(n_samples)
def show_all(self): con = dbapi2.connect(Infrastructure().get_db_path()) res = con.execute("Select * from commands") for r in res: iden, module_name, class_name, entry_name, command_name, active = r print("{}\t{}\t{}\t{}\t{}\t{}".format(iden, module_name, class_name, entry_name, command_name, active))
def delete_module(self, module_name): con = dbapi2.connect(Infrastructure().get_db_path()) con.execute("DELETE FROM commands WHERE module_name='"+module_name+"'") con.execute("COMMIT")
def insert(self, data): module_name, class_name, entry_name, command_name = data con = dbapi2.connect(Infrastructure().get_db_path()) con.execute("INSERT INTO commands (module_name, class_name, entry_name, command_name, active)\ VALUES ('"+module_name+"', '"+class_name+"', '"+entry_name+"', '"+command_name+"', '1')") con.execute("COMMIT")
def open_pyssistant_home(self): self.open_folder(Infrastructure().get_root_path())
def __init__(self): self.db_loc = Infrastructure().get_module_data_path("prompter")