def add_album(albums): album_properties = get_inputs([ 'artist name: ', 'album name: ', 'release year: ', 'genre: ', 'length: ' ]) albums.append(album_properties) file_handling.export_data(albums, mode='w')
def do_option(user_option, albums): if user_option == "1": genre = get_genre() try: by_genre = music_reports.get_albums_by_genre(albums,genre) display.print_albums_list(by_genre) while True: try: way_of_export = input("\nProvide mode a or w: \n") file_handling.export_data(by_genre, "albums_kuba.txt", way_of_export) break except ValueError: display.print_command_result("Wrond mode!") except ValueError: display.print_command_result("There is no genre like yours!") if user_option == "2": longest_album = music_reports.get_longest_album(albums) display.print_command_result("The longest album is: ") display.print_album_info(longest_album) if user_option == "3": total_albums_length = music_reports.get_total_albums_length(albums) display.print_command_result(f"Total length of albums is: {total_albums_length}.")
def test_export_data(self): import os tmp_filename = 'test_albums_data_tmp.txt' export_data(self.albums, tmp_filename) are_identical = test_helpers.compare_file_contents( self.test_filename, tmp_filename) os.remove(tmp_filename) self.assertTrue(are_identical)
def delete_album_by_artist_and_album_name(albums, artist, album_name): """ Deletes album of given name by given artist from list and updates data file :param list albums: currently existing albums :param str artist: artist who recorded the album :param str album_name: name of album to be deleted :returns: updated albums' list :rtype: list """ for counter, record in enumerate(albums): if record[0] == artist and record[1] == album_name: del albums[counter] file_handling.export_data(albums, filename='albums_data.txt', mode='w') return albums
def delete_album_by_artist_and_album_name(albums, artist, album_name): """ Deletes album of given name by given artist from list and updates data file :param list albums: currently existing albums :param str artist: artist who recorded the album :param str album_name: name of album to be deleted :returns: updated albums' list :rtype: list """ result = [] for album in albums: if not (artist == album[0] and album_name == album[1]): result.append(album) export_data(result) return result
def remove_album(albums): get_album_name = get_inputs(['album name: ']) for album in albums[:]: if album[ARTIST_NAME] == get_album_name[0]: albums.remove(album) file_handling.export_data(albums, mode='w')
display.print_multiple_albums(music_reports.DATA) ok=False artist = input("Artist please:") album_name = input("Name please:") if album_name != '': year = input("Year please:") if year.isdigit() and int(year) > 0: genre = input("Genre please:") time_input = input("Time please:") try: time_formated = time.strptime(time_input, '%H:%M') music_reports.add_record(music_reports.DATA, artist, album_name, year, genre, time_input) ok=True except: if time_input.isdigit(): time_input=':'.join([time_input,'00']) music_reports.add_record(music_reports.DATA, artist, album_name, year, genre, time_input) ok=True if ok: print('album ', artist, album_name, year, genre, time_input,' added') else: print('----------------------------------------------------------------------------------------') print("INVALID INPUT!") elif answer == 'e': file_handling.export_data(music_reports.DATA, 'external_file.txt', mode="w") elif answer == 'q': exit() else: print("Pick a valid letter!!! Geez...") print('----------------------------------------------------------------------------------------')