def update_words_all(): hannanum = Hannanum() db = db_connector.DbConnector() song_list = db.select_all() for song in song_list: if song['lyrics'] is not None and song['words'] is None: words = hannanum.nouns(song['lyrics']) words = sorted(set(words)) update_words(song['song_id'], ' '.join(words)) print('Words extraction done!')
def update_words(song_id, words): db = db_connector.DbConnector() db.connect() try: with db.connection.cursor() as cursor: sql = "update music_tree.song set words = %s where song_id=%s;" result = cursor.execute(sql, [words, song_id]) db.connection.commit() return result finally: db.close()
def song_modify(input): # input = [ 수정할 관련성, 분위기, 가사, words, 수정할 노래 id ] db = db_connector.DbConnector() db.connect() try: with db.connection.cursor() as cursor: sql = "update music_tree.song set relevance = %s, mood = %s, lyrics = %s, words = %s where song_id=%s;" result = cursor.execute(sql, input) db.connection.commit() return result finally: db.close()
def song_inquiry(input): # input = 조회할 노래 시작점 ( 배열 인덱스 ) / 시작점부터 50곡 id 오름차순 정렬해 불러옴 db = db_connector.DbConnector() db.connect() try: with db.connection.cursor() as cursor: sql = "SELECT * FROM music_tree.song order by song_id limit %s, 500;" cursor.execute(sql, input - 1) result = cursor.fetchall() return result finally: db.close()
def song_delete(input): # input = [ 삭제할 노래 id들 ] db = db_connector.DbConnector() db.connect() try: with db.connection.cursor() as cursor: sql = "delete from music_tree.song where song_id='%s';" for i in input: result = cursor.execute(sql, i) db.connection.commit() return result finally: db.close()
def songidSearch(): db = db_connector.DbConnector() db.connect() try: with db.connection.cursor() as cursor: sql = "SELECT melon_song_id FROM music_tree.song" cursor.execute(sql) result = cursor.fetchall() #result = pd.DataFrame(result, index = [0]) list = [] for i in result: list.append(i["melon_song_id"]) #print(list) return list finally: db.close()
def insertDB(data) : db = db_connector.DbConnector() db.connect() try: for i in range(len(data)): list = data.iloc[i, :].tolist() with db.connection.cursor() as cursor: sql = "INSERT INTO music_tree.song (melon_song_id, title, artist, group_type, gender, " \ "album, genre, rel_date, lyrics, relevance, mood, feat) " \ "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" cursor.execute(sql, list) db.connection.commit() return 1 except Exception as ex: # 에러 종류 return -1 # print('에러가 발생 했습니다 \n', ex) # ex는 발생한 에러의 이름을 받아오는 변수 finally: db.close() # fillCsv()
def __init__(self, displayWidth, displayHeigth, Caption, startingpage, *args): self.window = pygame.display.set_mode((display_width, display_heigth)) self.dbAgent = dbc.DbConnector("UserLoginData") pygame.display.set_caption(Caption) self.clock = pygame.time.Clock() self.username = "" if startingpage == "MainMenu" and len(args) != 0: self.playerID = args[0] self.username = self.getUsername(args[0]) else: self.playerID = None self.Username = True self.Password = False self.verificationError = False self.createdAccount = 0 self.sortByAlpha = 0 self.sortByNumeric = 0 self.sortByAmount = 0 self.difficulty = "Easy" self.dropDown = False self.W = Widgets(self.window) self.redrawWindow(startingpage)
import db_connector dbCon = db_connector.DbConnector() dbCon.get_instance('localhost', 'abills', 'sqlpassword', 'pasichnyk') class Users: _db_connector = None def __init__(self, _connector): if not self._db_connector: self._db_connector = _connector def info(self, attr): search_fields = self._get_search_fields(attr) query = "SELECT " + search_fields[ 'SHOW'] + " FROM users u " + search_fields['WHERE'] return self._db_connector.query(query, attr) def update(self, attr): search_fields = self._get_search_fields(attr) query = "UPDATE users u " + search_fields['SET'] + " " + search_fields[ 'WHERE'] return self._db_connector.query(query, attr) def delete(self, attr): search_fields = self._get_search_fields(attr) query = "DELETE FROM users " + search_fields['WHERE_WITHOUT_PREFIX'] return self._db_connector.query(query, attr) def insert(self, attr):
red = (186, 18, 0) delete_red = (241, 157, 157) play_green = (160, 241, 157) btn = (157, 209, 241) highlight_btn = (200, 224, 244) #Fonts pygame.font.init() font = pygame.font.SysFont("comicsans", 40) font_small = pygame.font.SysFont("comicsans", 24) font_40 = pygame.font.SysFont("robotoregularttf", 40) font_32 = pygame.font.SysFont("robotoregularttf", 32) font_24 = pygame.font.SysFont("robotoregularttf", 24) font_20 = pygame.font.SysFont("robotoregularttf", 20) dbAgent = dbc.DbConnector("Sudoku") class Grid: sudoku = generator.Sudoku(9, 43) #43 board = sudoku.returnBoard() def __init__(self, rows, cols, width, height, win): self.rows = rows self.cols = cols self.cubes = [[ Cube(self.board[i][j], i, j, width, height) for j in range(cols) ] for i in range(rows)] self.width = width self.height = height self.model = None
def __init__(self): self.LoginManager = dbc.DbConnector("UserLoginData")
def deleteRow(self, *args): try: dbAgent = dbc.DbConnector("Sudoku") dbAgent.deleteSudokuGame(args[1][4]) except: self.drawErrorPage()
def __init__(self, ID): self.dbAgent = dbc.DbConnector("Sudoku") self.UserID = ID