Compare commits
9 Commits
f446120184
...
ee23e0f0e9
| Author | SHA1 | Date | |
|---|---|---|---|
| ee23e0f0e9 | |||
| b6dc9bd87b | |||
| 83c1d82387 | |||
| 488a97f3f6 | |||
| 626dfc25fc | |||
| 986eb94add | |||
| 8c311ea739 | |||
| a75a241f30 | |||
| 10894187b2 |
25
README.md
25
README.md
@@ -11,14 +11,27 @@ At the moment, an alpha version is undertaken, with these features:
|
|||||||
- The sqlite-database holds a growing number of piano-solo pieces, together with their exact catalogue-numbers and composers.
|
- The sqlite-database holds a growing number of piano-solo pieces, together with their exact catalogue-numbers and composers.
|
||||||
- Prepared in this database is a table for users (pianists), that marks which of the pieces can be played.
|
- Prepared in this database is a table for users (pianists), that marks which of the pieces can be played.
|
||||||
|
|
||||||
### Application
|
### Application and usage
|
||||||
|
|
||||||
- Create new users
|
- Create new users (`n username`)
|
||||||
- Set an active user
|
- Show users (`su`)
|
||||||
- (planned) Show the pieces stored in the database
|
- Set an active user (`a number_of_user`)
|
||||||
- (planned) Mark pieces as masterd for the active user
|
- Show the pieces stored in the database (`s`)
|
||||||
|
- Mark pieces as mastered for the active user (`m number_of_work`)
|
||||||
|
- Show pieces by composer (`sc` shows composers, `c number_of_composer` shows pieces)
|
||||||
|
- Show movements through pieces (`sp piece_number`)
|
||||||
|
- Mark movement as mastered for active user (`m number_of_work number_of_movement`)
|
||||||
|
- (planned) Show possible commands (`h`)
|
||||||
|
- (planned) Show mastered works/movements for activated user
|
||||||
|
- (planned) Save recordings per movement in db
|
||||||
|
- (planned) Listen to saved recordings
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- Python 3.9 or higher
|
- Python 3.9 or higher
|
||||||
- Enough disk space to hold the database
|
- Enough disk space to hold the database
|
||||||
|
- run `python builddb.py` to build the SQLite-database-file before running `python rep_cli.py`
|
||||||
|
|
||||||
|
## Known Bugs
|
||||||
|
|
||||||
|
- Marking a piece as mastered the second time, the database won’t insert the entry and the program will crash
|
||||||
152
rep_cli.py
152
rep_cli.py
@@ -6,8 +6,19 @@ class Session:
|
|||||||
self.user = -1
|
self.user = -1
|
||||||
self.db_agent = db_agent
|
self.db_agent = db_agent
|
||||||
self.resultstring = 'no results yet'
|
self.resultstring = 'no results yet'
|
||||||
|
self.commands = {'a': (self.set_user, ''),
|
||||||
|
'c': (self.show_composers, ''),
|
||||||
|
'm': (self.mark_work_as_mastered, ''),
|
||||||
|
'n': (self.create_new_user, ''),
|
||||||
|
's': (self.show_works, ''),
|
||||||
|
'sc': (self.show_works, ''),
|
||||||
|
'sp': (self.show_movements, ''),
|
||||||
|
'su': (self.show_users, ''),
|
||||||
|
'q': (self.quit, '')
|
||||||
|
}
|
||||||
|
|
||||||
def set_user(self, db_index):
|
def set_user(self, arguments):
|
||||||
|
db_index = arguments[0]
|
||||||
self.user = db_index
|
self.user = db_index
|
||||||
return 'User set'
|
return 'User set'
|
||||||
|
|
||||||
@@ -27,31 +38,44 @@ class Session:
|
|||||||
|
|
||||||
def invoke_command(self, command, arguments):
|
def invoke_command(self, command, arguments):
|
||||||
self.resultstring = ''
|
self.resultstring = ''
|
||||||
if command == 'a':
|
if command in self.commands.keys():
|
||||||
self.resultstring += self.set_user(arguments[0])
|
self.resultstring += self.commands[command][0](arguments)
|
||||||
elif command == 'n':
|
|
||||||
self.create_new_user(arguments[0], arguments[1])
|
|
||||||
self.resultstring += f'Created new user {arguments[0]} {arguments[1]}.'
|
|
||||||
elif command == 's':
|
|
||||||
self.resultstring += self.show_works()
|
|
||||||
elif command == 'su':
|
|
||||||
self.resultstring += self.show_users()
|
|
||||||
elif command == 'q':
|
|
||||||
self.resultstring += 'Bye-bye'
|
|
||||||
else:
|
else:
|
||||||
self.resultstring += 'Could not understand command.'
|
self.resultstring += 'Could not understand command.'
|
||||||
|
|
||||||
def result(self):
|
def result(self):
|
||||||
return self.resultstring
|
return self.resultstring
|
||||||
|
|
||||||
def create_new_user(self, first_name, name):
|
def create_new_user(self, arguments):
|
||||||
|
first_name, name = arguments[0], arguments[1]
|
||||||
sql_command = f'''
|
sql_command = f'''
|
||||||
INSERT INTO pianist (first_name, sec_name)
|
INSERT INTO pianist (first_name, sec_name)
|
||||||
VALUES ("{first_name}", "{name}");
|
VALUES ("{first_name}", "{name}");
|
||||||
'''
|
'''
|
||||||
self.db_agent.execute(sql_command)
|
self.db_agent.execute(sql_command)
|
||||||
|
return f'Created new user {first_name} {name}.'
|
||||||
|
|
||||||
def show_users(self):
|
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_movements(self, arguments):
|
||||||
|
work_id = arguments[0]
|
||||||
|
work = work_under_id(work_id, self.db_agent)
|
||||||
|
fun_resultstring = ''
|
||||||
|
for mov_number in work.values['movements'].keys():
|
||||||
|
fun_resultstring += f'{mov_number}. {work.pretty_mov(mov_number)}\n'
|
||||||
|
return fun_resultstring
|
||||||
|
|
||||||
|
def show_users(self, _):
|
||||||
sql_command = '''
|
sql_command = '''
|
||||||
SELECT * FROM pianist;
|
SELECT * FROM pianist;
|
||||||
'''
|
'''
|
||||||
@@ -61,19 +85,54 @@ 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, arguments):
|
||||||
sql_command = '''
|
if len(arguments) > 0:
|
||||||
|
restraint = f'comp_id = {arguments[0]}'
|
||||||
|
else:
|
||||||
|
restraint = '1 = 1'
|
||||||
|
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!
|
||||||
return ''
|
list_of_works = list()
|
||||||
|
for item in list_of_work_ids:
|
||||||
|
list_of_works.append(work_under_id(item[0], self.db_agent))
|
||||||
|
fun_resultstring = ''
|
||||||
|
for work in list_of_works:
|
||||||
|
fun_resultstring += f'{work.id()}: {work.pretty_string()}\n'
|
||||||
|
return fun_resultstring
|
||||||
|
|
||||||
|
def mark_work_as_mastered(self, arguments):
|
||||||
|
work_id = arguments[0]
|
||||||
|
resultstring = 'adding:\n'
|
||||||
|
work = work_under_id(work_id, self.db_agent)
|
||||||
|
if len(arguments) > 1:
|
||||||
|
mov_number = int(arguments[1])
|
||||||
|
sql_command = f'''
|
||||||
|
INSERT INTO is_able_to_play (work_id, mov_id, pianist_id)
|
||||||
|
VALUES ({work_id}, {mov_number}, {self.user})
|
||||||
|
'''
|
||||||
|
self.db_agent.execute(sql_command)
|
||||||
|
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
||||||
|
else:
|
||||||
|
for mov_number in work.values['movements'].keys():
|
||||||
|
sql_command = f'''
|
||||||
|
INSERT INTO is_able_to_play (work_id, mov_id, pianist_id)
|
||||||
|
VALUES ({work_id}, {mov_number}, {self.user})
|
||||||
|
'''
|
||||||
|
self.db_agent.execute(sql_command)
|
||||||
|
resultstring += f'{work.pretty_mov(mov_number)}\n'
|
||||||
|
return resultstring
|
||||||
|
|
||||||
|
def quit(self, _):
|
||||||
|
return 'Bye bye!'
|
||||||
|
|
||||||
# End session
|
# End session
|
||||||
|
|
||||||
class Werk_unter_id:
|
class work_under_id:
|
||||||
# con = sqlite3.connect('repertoire.db')
|
# con = sqlite3.connect('repertoire.db')
|
||||||
# reader = con.cursor()
|
# reader = con.cursor()
|
||||||
|
|
||||||
@@ -113,7 +172,7 @@ class Werk_unter_id:
|
|||||||
saetze[satz[1]] = satz[2], satz[3], satz[4]
|
saetze[satz[1]] = satz[2], satz[3], satz[4]
|
||||||
if not satz[2] is None:
|
if not satz[2] is None:
|
||||||
nummern.add(satz[2])
|
nummern.add(satz[2])
|
||||||
self.values['Sätze'] = saetze
|
self.values['movements'] = saetze
|
||||||
if len(nummern) == 1:
|
if len(nummern) == 1:
|
||||||
self.sätze_unter_nummer = True
|
self.sätze_unter_nummer = True
|
||||||
self.values['numb'] = nummern.pop()
|
self.values['numb'] = nummern.pop()
|
||||||
@@ -127,6 +186,51 @@ class Werk_unter_id:
|
|||||||
else:
|
else:
|
||||||
return sammlung
|
return sammlung
|
||||||
|
|
||||||
|
def id(self):
|
||||||
|
return self.values['id']
|
||||||
|
|
||||||
|
def pretty_string(self):
|
||||||
|
ret_str = ''
|
||||||
|
for key in ['first_name', 'name',
|
||||||
|
'title', 'opus',
|
||||||
|
'main_key', 'alias',
|
||||||
|
'work_directory','wd_number']:
|
||||||
|
if not self.values[key] is None:
|
||||||
|
if key == 'opus':
|
||||||
|
ret_str += f'op. {self.values[key]} '
|
||||||
|
else:
|
||||||
|
ret_str += f'{self.values[key]} '
|
||||||
|
return ret_str
|
||||||
|
|
||||||
|
def pretty_mov(self, mov_number):
|
||||||
|
ret_str = ''
|
||||||
|
for key in ['first_name', 'name',
|
||||||
|
'title', 'mov_title', 'opus', 'numb',
|
||||||
|
'main_key', 'alias',
|
||||||
|
'movements',
|
||||||
|
'work_directory','wd_number']:
|
||||||
|
if key in self.values.keys() and not self.values[key] is None:
|
||||||
|
if key == 'opus':
|
||||||
|
ret_str += f'op. {self.values[key]} '
|
||||||
|
elif key == 'name':
|
||||||
|
ret_str += f'{self.values[key]}, '
|
||||||
|
elif key == 'numb':
|
||||||
|
ret_str += f'Nr. {self.values[key]} '
|
||||||
|
elif key == 'movements':
|
||||||
|
if self.values[key][mov_number][1] is None:
|
||||||
|
ret_str += ''
|
||||||
|
else:
|
||||||
|
if len(self.values[key]) > 1:
|
||||||
|
ret_str += f'{mov_number}. {self.values[key][mov_number][1]} '
|
||||||
|
else:
|
||||||
|
ret_str += f'{self.values[key][mov_number][1]} '
|
||||||
|
elif key == 'title':
|
||||||
|
if self.values['mov_title'] is None:
|
||||||
|
ret_str += f'{self.values[key]} '
|
||||||
|
else:
|
||||||
|
ret_str += f'{self.values[key]} '
|
||||||
|
return ret_str
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
ret_str = ''
|
ret_str = ''
|
||||||
for key, value in self.values.items():
|
for key, value in self.values.items():
|
||||||
@@ -134,12 +238,12 @@ class Werk_unter_id:
|
|||||||
ret_str += f'{key}: {value}\n'
|
ret_str += f'{key}: {value}\n'
|
||||||
return ret_str
|
return ret_str
|
||||||
|
|
||||||
# End Werk_unter_id
|
# End work_under_id
|
||||||
|
|
||||||
def parse_user_input(user_in):
|
def parse_user_input(user_in, session):
|
||||||
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', 'n', 'q', 's', 'su'):
|
if command in session.commands.keys():
|
||||||
arguments = split_user_in[1:]
|
arguments = split_user_in[1:]
|
||||||
return (command, arguments)
|
return (command, arguments)
|
||||||
else:
|
else:
|
||||||
@@ -149,9 +253,8 @@ def command_line_loop(session):
|
|||||||
user_in = ''
|
user_in = ''
|
||||||
while not user_in == 'q':
|
while not user_in == 'q':
|
||||||
user_in = input(f'Piano-Repertoire: {session.get_active_user()} >>> ')
|
user_in = input(f'Piano-Repertoire: {session.get_active_user()} >>> ')
|
||||||
command, arguments = parse_user_input(user_in)
|
command, arguments = parse_user_input(user_in, session)
|
||||||
session.invoke_command(command, arguments)
|
session.invoke_command(command, arguments)
|
||||||
# print(f'command: {command}, arguments: {arguments}')
|
|
||||||
print(session.result())
|
print(session.result())
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -164,6 +267,5 @@ def main():
|
|||||||
con.close()
|
con.close()
|
||||||
print('db-connection closed. Bye-bye!')
|
print('db-connection closed. Bye-bye!')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user