New feature: sc shows composers, and c noc shows pieces by composer

This commit is contained in:
2023-11-08 07:05:58 +01:00
parent 8c311ea739
commit 986eb94add
2 changed files with 21 additions and 4 deletions

View File

@@ -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

View File

@@ -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: