diff --git a/README.md b/README.md index 6918cca..63a70b0 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ At the moment, an alpha version is undertaken, with these features: - Set an active user (`a number_of_user`) - Show the pieces stored in the database (`s`) - Mark pieces as mastered for the active user (`m number_of_work`) -- (planned) Show pieces by composer +- Show pieces by composer (`sc` shows composers, `c number_of_composer` shows pieces) - (planned) Show movements through pieces ## Requirements diff --git a/rep_cli.py b/rep_cli.py index aaa9029..ee0dd84 100644 --- a/rep_cli.py +++ b/rep_cli.py @@ -29,6 +29,8 @@ class Session: self.resultstring = '' if command == 'a': self.resultstring += self.set_user(arguments[0]) + elif command == 'c': + self.resultstring += self.show_composers() elif command == 'm': self.resultstring += self.mark_work_as_mastered(arguments[0]) elif command == 'n': @@ -36,6 +38,8 @@ class Session: self.resultstring += f'Created new user {arguments[0]} {arguments[1]}.' elif command == 's': self.resultstring += self.show_works() + elif command == 'sc': + self.resultstring += self.show_works(restraint=f'comp_id = {arguments[0]}') elif command == 'su': self.resultstring += self.show_users() elif command == 'q': @@ -53,6 +57,18 @@ class Session: ''' self.db_agent.execute(sql_command) + def show_composers(self): + sql_command = ''' + SELECT id, first_name, name + FROM composer + ORDER BY name + ''' + result_list = self.db_agent.execute(sql_command).fetchall() + fun_resultstring = '' + for item in result_list: + fun_resultstring += f'{item[0]}: {item[2]}, {item[1]}\n' + return fun_resultstring + def show_users(self): sql_command = ''' SELECT * FROM pianist; @@ -63,10 +79,11 @@ class Session: fun_resultstring += f'{item[0]}: {item[1]} {item[2]}\n' return fun_resultstring - def show_works(self): - sql_command = ''' + def show_works(self, restraint='1=1'): + sql_command = f''' SELECT id FROM work + WHERE {restraint} ''' list_of_work_ids = self.db_agent.execute(sql_command).fetchall() # GET WORKS OUT! @@ -203,7 +220,7 @@ class work_under_id: def parse_user_input(user_in): split_user_in = user_in.split() command = split_user_in[0] - if command in ('a', 'm', 'n', 'q', 's', 'su'): + if command in ('a', 'c', 'm', 'n', 'q', 's', 'sc', 'su'): arguments = split_user_in[1:] return (command, arguments) else: