def __init__(self): self.dbh = DbHandler() self.dbh.initmetadata() self.player = Player() self.sh = SpotifyHandler() self.rootnode = self.initbrowsernodes() self.curnode = self.rootnode self.mostrecentplayer = ''
def get_checker_name(path_to_db, topic_name): print( "\nPlease provide the checker name (e.g. the name of the file, including extension)" ) all_checker_names = DbHandler.get_checker_names(path_to_db) while True: checker_name = input("Checker name: ") if checker_name in all_checker_names: print("Checker name already exists for topic " + DbHandler.get_topic_for_checker(path_to_db, checker_name)) else: if not os.path.exists("scripts/" + topic_name.lower() + "/" + checker_name): print("File scripts/" + topic_name.lower() + "/" + checker_name + " not found.") else: return checker_name
def get_task_name(path_to_db): print("\nPlease insert the task name, case sensitive. It must not exist.") all_tasks = DbHandler.get_all_tasks(path_to_db) all_tasks = [x.lower() for x in all_tasks] while True: task_name = input("Task name: ") if task_name.lower() in all_tasks: print("This task already exists.") else: return task_name
def get_task_name(path_to_db): print( "\nPlease insert the task name, case insensitive. It must not exist.") all_tasks = DbHandler.get_all_tasks(path_to_db) while True: task_name = input("Task name: ") for task in all_tasks: if task.lower() == task_name.lower(): return task print("This task does not exist.")
class Worker(object): """ Interacts with database""" mydb = None def __init__(self, dburl): if not dburl: return False self.mydb = DbHandler() self.mydb.createengine(url='sqlite:///:memory:') def registeralert(self, alert=None): if alert is None: return False session = self.mydb.getsession() session.add(alert) session.commit() return True def getalerts(self): alerts = self.mydb.getsession().query(Alert) return alerts
def main(): parser = argparse.ArgumentParser() parser.add_argument('-d', '--db', help='Sqlite database location', type=str, required=True) args = parser.parse_args() if not check_db_exists(args.db): print("The database file does not exist. Perhaps you got the path wrong?" + \ " If it's a new database, please create it manually.") return greet() task_name = get_task_name(args.db) DbHandler.remove_task_from_db(args.db, task_name) print("Done")
class Worker(object): """ Interacts with database""" mydb = None def __init__(self, dburl): if not dburl: return False self.mydb = DbHandler() self.mydb.createengine(url = 'sqlite:///:memory:') def registeralert(self, alert = None): if alert is None : return False session = self.mydb.getsession() session.add(alert) session.commit() return True def getalerts(self): alerts = self.mydb.getsession().query(Alert) return alerts
def get_checker_language(path_to_db): print( "\nPlease provide the checker language. Currently supported languages:" ) all_checker_languages = DbHandler.get_checker_languages(path_to_db) for language in all_checker_languages: print(language) while True: language = input("Checker language: ") if language not in all_checker_languages: print("Language does not exist. Please select an existing one.") else: return language
def get_topic_name(path_to_db): print("\nCurrent list of topics:\n") topics = DbHandler.list_topics(path_to_db) for topic in topics: print(topic) print( "\nPlease insert the topic name, or a new one, case insensitive. It cannot contain spaces." ) while True: topic_name = input("Topic name: ") if " " in topic_name: print("It cannot contain spaces.") else: if not os.path.exists("scripts/" + topic_name.lower()): print("Directory scripts/" + topic_name.lower() + " not found.") else: for topic in topics: if topic_name.lower() == topic.lower(): return topic return topic_name
class Browser: 'Class for traversing the browser structure and controlling local media playback' def __init__(self): self.dbh = DbHandler() self.dbh.initmetadata() self.player = Player() self.sh = SpotifyHandler() self.rootnode = self.initbrowsernodes() self.curnode = self.rootnode self.mostrecentplayer = '' def initbrowsernodes(self): root = BrowserNode('root', self.dbh, self.sh) localmedia = BrowserNode('Local media', self.dbh, self.sh) spotify = BrowserNode('Spotify', self.dbh, self.sh, 'spotify playlists') restart = BrowserNode('Restart', self.dbh, self.sh, 'restart') albumartists = BrowserNode('Album artists', self.dbh, self.sh, 'tags', 'albumartist') artists = BrowserNode('Artists', self.dbh, self.sh, 'tags', 'artist') composers = BrowserNode('Composers', self.dbh, self.sh, 'tags', 'composer') genres = BrowserNode('Genres', self.dbh, self.sh, 'tags', 'genre') localmedia.addchild(albumartists) localmedia.addchild(artists) localmedia.addchild(composers) localmedia.addchild(genres) root.addchild(localmedia) root.addchild(spotify) root.addchild(restart) return root def curlist(self): children = [] for child in self.curnode.getchildren(): children.append(str(child)) return children def select(self, index): selection = self.curnode.getchild(index) if selection.querytarget == 'play local': self.mostrecentplayer = 'local' self.sh.stop() filenames = [] for child in self.curnode.getchildren(): filenames.append(child.querysearch) self.player.play(filenames, index) elif selection.querytarget == 'play spotify': self.mostrecentplayer = 'spotify' self.player.stop() self.sh.selecttrack(selection.querysearch) self.sh.play() elif selection.querytarget == 'restart': self.restart_program() else: self.curnode = self.curnode.getchild(index) return self.curlist() def back(self): parent = self.curnode.getparent() if parent: self.curnode = parent return self.curlist() def togglepause(self): if self.mostrecentplayer == 'local': self.player.pause() elif self.mostrecentplayer == 'spotify': self.sh.togglepause() def next(self): if self.mostrecentplayer == 'local': self.player.next() elif self.mostrecentplayer == 'spotify': self.sh.next() def prev(self): if self.mostrecentplayer == 'local': self.player.prev() elif self.mostrecentplayer == 'spotify': self.sh.prev() def restart_program(self): python = sys.executable os.execl(python, python, *sys.argv)
def insert_data_in_db(path_to_db, topic, task, checker_name, checker_language, description, added_by): topic_id = DbHandler.insert_topic(path_to_db, topic) DbHandler.insert_task(path_to_db, topic_id, task, checker_name, checker_language, description, added_by)
def __init__(self, dburl): if not dburl: return False self.mydb = DbHandler() self.mydb.createengine(url='sqlite:///:memory:')
self.ui.widget.canvas.ax1.plot( niveis_formacao[val - len(self.cursos) - 3].totalH) self.ui.widget.canvas.ax2.plot( niveis_formacao[val - len(self.cursos) - 3].totalM) self.ui.widget.canvas.ax3.plot( niveis_formacao[val - len(self.cursos) - 3].totalHM) self.ui.widget.canvas.ax1.legend('HMT') self.ui.widget.canvas.ax1.set_xticklabels( ('9596', '9798', '9900', '0102', '0304', '0506', '0708', '0910', '1112')) self.ui.widget.canvas.draw() if __name__ == "__main__": db = DbHandler("database/Inscritos.sqlite3") db.createTable("inscritos") db.writeToTable("Inscritos_2010-2011.xls") db.dbToCsv("curso", ["Computadores", "Informática"]) cursos = db.getInscritosCurso("curso", ["Computadores", "Informática"]) niveis_formacao = db.getInscritosNF() db.closeConnection() #Parte gráfica do programa app = QtGui.QApplication(sys.argv) myapp = GUIForm(cursos, niveis_formacao) myapp.show() sys.exit(app.exec_())
self.ui.widget.canvas.ax1.set_ylabel(u'Número de inscritos') self.ui.widget.canvas.ax1.set_title(u'Número de inscritos/ano lectivo') self.ui.widget.canvas.ax1.plot(niveis_formacao[val-len(self.cursos)-3].totalH) self.ui.widget.canvas.ax2.plot(niveis_formacao[val-len(self.cursos)-3].totalM) self.ui.widget.canvas.ax3.plot(niveis_formacao[val-len(self.cursos)-3].totalHM) self.ui.widget.canvas.ax1.legend('HMT') self.ui.widget.canvas.ax1.set_xticklabels( ('9596', '9798', '9900', '0102', '0304', '0506', '0708', '0910', '1112') ) self.ui.widget.canvas.draw() if __name__ == "__main__": db = DbHandler("database/Inscritos.sqlite3") db.createTable("inscritos") db.writeToTable("Inscritos_2010-2011.xls") db.dbToCsv("curso",["Computadores","Informática"]) cursos = db.getInscritosCurso("curso", ["Computadores","Informática"]) niveis_formacao = db.getInscritosNF() db.closeConnection() #Parte gráfica do programa app = QtGui.QApplication(sys.argv) myapp = GUIForm(cursos, niveis_formacao) myapp.show() sys.exit(app.exec_())
def __init__(self, dburl): if not dburl: return False self.mydb = DbHandler() self.mydb.createengine(url = 'sqlite:///:memory:')