New feature: sc shows composers, and c noc shows pieces by composer
This commit is contained in:
@@ -18,7 +18,7 @@ At the moment, an alpha version is undertaken, with these features:
|
|||||||
- Set an active user (`a number_of_user`)
|
- Set an active user (`a number_of_user`)
|
||||||
- Show the pieces stored in the database (`s`)
|
- Show the pieces stored in the database (`s`)
|
||||||
- Mark pieces as mastered for the active user (`m number_of_work`)
|
- 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
|
- (planned) Show movements through pieces
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|||||||
23
rep_cli.py
23
rep_cli.py
@@ -29,6 +29,8 @@ class Session:
|
|||||||
self.resultstring = ''
|
self.resultstring = ''
|
||||||
if command == 'a':
|
if command == 'a':
|
||||||
self.resultstring += self.set_user(arguments[0])
|
self.resultstring += self.set_user(arguments[0])
|
||||||
|
elif command == 'c':
|
||||||
|
self.resultstring += self.show_composers()
|
||||||
elif command == 'm':
|
elif command == 'm':
|
||||||
self.resultstring += self.mark_work_as_mastered(arguments[0])
|
self.resultstring += self.mark_work_as_mastered(arguments[0])
|
||||||
elif command == 'n':
|
elif command == 'n':
|
||||||
@@ -36,6 +38,8 @@ class Session:
|
|||||||
self.resultstring += f'Created new user {arguments[0]} {arguments[1]}.'
|
self.resultstring += f'Created new user {arguments[0]} {arguments[1]}.'
|
||||||
elif command == 's':
|
elif command == 's':
|
||||||
self.resultstring += self.show_works()
|
self.resultstring += self.show_works()
|
||||||
|
elif command == 'sc':
|
||||||
|
self.resultstring += self.show_works(restraint=f'comp_id = {arguments[0]}')
|
||||||
elif command == 'su':
|
elif command == 'su':
|
||||||
self.resultstring += self.show_users()
|
self.resultstring += self.show_users()
|
||||||
elif command == 'q':
|
elif command == 'q':
|
||||||
@@ -53,6 +57,18 @@ class Session:
|
|||||||
'''
|
'''
|
||||||
self.db_agent.execute(sql_command)
|
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):
|
def show_users(self):
|
||||||
sql_command = '''
|
sql_command = '''
|
||||||
SELECT * FROM pianist;
|
SELECT * FROM pianist;
|
||||||
@@ -63,10 +79,11 @@ class Session:
|
|||||||
fun_resultstring += f'{item[0]}: {item[1]} {item[2]}\n'
|
fun_resultstring += f'{item[0]}: {item[1]} {item[2]}\n'
|
||||||
return fun_resultstring
|
return fun_resultstring
|
||||||
|
|
||||||
def show_works(self):
|
def show_works(self, restraint='1=1'):
|
||||||
sql_command = '''
|
sql_command = f'''
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM work
|
FROM work
|
||||||
|
WHERE {restraint}
|
||||||
'''
|
'''
|
||||||
list_of_work_ids = self.db_agent.execute(sql_command).fetchall()
|
list_of_work_ids = self.db_agent.execute(sql_command).fetchall()
|
||||||
# GET WORKS OUT!
|
# GET WORKS OUT!
|
||||||
@@ -203,7 +220,7 @@ class work_under_id:
|
|||||||
def parse_user_input(user_in):
|
def parse_user_input(user_in):
|
||||||
split_user_in = user_in.split()
|
split_user_in = user_in.split()
|
||||||
command = split_user_in[0]
|
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:]
|
arguments = split_user_in[1:]
|
||||||
return (command, arguments)
|
return (command, arguments)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user