def main():
    """
    Calls all interaction between user and program, handles program menu
    and user inputs. It should repeat displaying menu and asking for
    input until that moment.

    You should create new functions and call them from main whenever it can
    make the code cleaner
    """


    print_command_result('MUSIC LIBARY \n')

    while True:
        global file_albums
        global MENU
        print_command_result('Menu\n')
        print_program_menu(MENU)
        print('___________________________________________________\n')
        user_input =input('Please chose one of teh following option:')
        if user_input =='1':
            print_command_result('LIST OF ALBUMS\n')
            print_albums_list(file_albums)
        elif user_input =='2':
            genre = input('Enter a music genre: ')
            gen_albums = get_albums_by_genre(file_albums, genre)
            print_command_result('all of the file data\n')
            print_albums_list(gen_albums)
        elif user_input=='3':
            genre =input('Enter genre: \n')
            last_oldest_by_gen = get_last_oldest_of_genre(file_albums,genre)
            print_command_result('Oldest album of chosen genre:\n')
            print_album_info(last_oldest_by_gen)
        elif user_input =='4':
            longest_album = get_longest_album(file_albums)
            print_command_result('Longest album is:\n')
            print_album_info(longest_album)
        elif user_input =='5':
            lenght_f_album = get_total_albums_length(file_albums)
            print_command_result('"Total albums lenght is(float):\n"')
            print_command_result(str(lenght_f_album))
        elif user_input =='6':
            year = input("Enter choosen year: ")
            album_years = get_album_by_year(file_albums,year)
            print_command_result('Album chosen by year\n')
            print_albums_list(album_years)
        elif user_input =='7':
            last_oldest = get_last_oldest(file_albums)
            print_command_result('oldest album\n')
            print_albums_list(last_oldest)
        elif user_input =='8':
            genre_stat =get_genre_stats(file_albums)
            print_command_result('Statistic\n')
            print_album_info(genre_stat)
        elif user_input =='9':
            break
        else:
            continue
Esempio n. 2
0
    def test_get_genre_stats(self):
        expected = {
            "hip hop": 1,
            "progressive rock": 2,
            "ancient": 1,
            "pop": 3,
            "rock": 2,
            "hard rock": 2
        }
        genre_stats = get_genre_stats(self.albums)

        self.assertDictEqual(genre_stats, expected)
Esempio n. 3
0
def main():
    """
    Calls all interaction between user and program, handles program menu
    and user inputs. It should repeat displaying menu and asking for
    input until that moment.

    You should create new functions and call them from main whenever it can
    make the code cleaner
    """
    choose = None

    while choose != 5:

        commands = [
            'Get albums by genre', 'Qunatity of albums in each genre',
            'Get album with biggest value in length field',
            'Get last album with earliest release year',
            'Get last album with earliest release year in given genre', 'Exit'
        ]
        display.print_albums_list(albums)
        display.print_program_menu(commands)

        choose = int(input("Please provide your choose: "))
        message = commands[choose]
        display.print_command_result(message)
        if message == 'Get albums by genre':
            genre = input("Pleae provide a music genre: ")
            albums_data = music_reports.get_albums_by_genre(albums, genre)
            for album in albums_data:
                display.print_album_info(album)
        if message == 'Qunatity of albums in each genre':
            result = music_reports.get_genre_stats(albums)
            message = str(result)
            display.print_command_result(message)
        if message == 'Get album with biggest value in length field':
            albums_data = music_reports.get_longest_album(albums)
            for album in albums_data:
                display.print_album_info(album)
        if message == 'Get last album with earliest release year':
            albums_data = music_reports.get_last_oldest(albums)
            for album in albums_data:
                display.print_album_info(album)
        else:
            print("dupas")
Esempio n. 4
0
def choose_option():
    albums = file_handling.import_data()
    choose_option = get_inputs(['Enter option number: '])
    option = choose_option[0]
    if option == '0':
        add_album(albums)
    elif option == '1':
        remove_album(albums)
    elif option == '2':
        get_genre = get_inputs(['genre: '])
        try:
            display.print_albums_list(
                music_reports.get_albums_by_genre(albums, get_genre[0]))
        except ValueError as err:
            display.print_command_result(str(err))
    elif option == '3':
        display.print_album_info(music_reports.get_longest_album(albums))
    elif option == '4':
        total_albums_length = music_reports.get_total_albums_length(albums)
        display.print_command_result(
            f'Total albums length in mins: {total_albums_length}')
    elif option == '5':
        genre_stats = music_reports.get_genre_stats(albums)
        for genre_name, amount_of_albums in genre_stats.items():
            display.print_command_result(f'{genre_name}|{amount_of_albums}')
    elif option == '6':
        oldest_album = music_reports.get_last_oldest(albums)
        display.print_album_info(oldest_album)
    elif option == '7':
        get_genre = get_inputs(['genre: '])
        oldest_album_in_genre = music_reports.get_last_oldest_of_genre(
            albums, get_genre[0])
        display.print_album_info(oldest_album_in_genre)
    elif option == '8':
        sys.exit()
    else:
        raise ValueError("There is no such option")
Esempio n. 5
0
def main():
    """
    Calls all interaction between user and program, handles program menu
    and user inputs. It should repeat displaying menu and asking for
    input until that moment.

    You should create new functions and call them from main whenever it can
    make the code cleaner
    """
    menu_commands = [
        "Delete album", "Get albums by genre",
        "How many albums are in each genre",
        "Get last album with earliest release year",
        "Get last album with earliest release year in given genre",
        "Get longest album", "Get sum of lengths of all albums in minutes",
        "Quit program"
    ]

    while True:
        albums_data = file_handling.import_data(filename='albums_data.txt')
        display.print_command_result("Choose your option:")
        display.print_program_menu(menu_commands)
        choice = input("What would you like to do? ")
        if choice == "0":
            display.print_albums_list(albums_data)
            artist = input("Which artist would you like to remove?")
            album_name = input("Which album would you like to remove?")
            delete_album_by_artist_and_album_name(albums_data, artist,
                                                  album_name)
        elif choice == "1":
            genre = input("Which genre would you like to check?")
            try:
                genre_list = music_reports.get_albums_by_genre(
                    albums_data, genre)
                display.print_albums_list(genre_list)
            except ValueError:
                display.print_command_result("Wrong genre does not match")

        elif choice == "2":
            message = str(music_reports.get_genre_stats(albums_data))
            display.print_command_result(message)

        elif choice == "3":
            oldest = music_reports.get_last_oldest(albums_data)
            display.print_album_info(oldest)

        elif choice == "4":
            genre = input("Which genre would you like to check?")
            try:
                oldest_from_genre = music_reports.get_last_oldest_of_genre(
                    albums_data, genre)
                display.print_album_info(oldest_from_genre)
            except ValueError:
                display.print_command_result("Wrong genre does not match")

        elif choice == "5":
            longest = music_reports.get_longest_album(albums_data)
            display.print_album_info(longest)

        elif choice == "6":
            message = str(music_reports.get_total_albums_length(albums_data))
            display.print_command_result(message)

        elif choice == "7":
            sys.exit()

        else:
            display.print_command_result("There's no such option. Try again.")
Esempio n. 6
0
def main():
    """
    Calls all interaction between user and program, handles program menu
    and user inputs. It should repeat displaying menu and asking for
    input until that moment.

    You should create new functions and call them from main whenever it can
    make the code cleaner
    """
    menu = [
        'Get album by genre.', 'Get genre stats.', 'Get longest album.',
        'Get last album with earliest release year by genre',
        'Get sum of lengths of all albums in minutes', 'Delete album.'
    ]
    albums = file_handling.import_data()
    while True:

        display.print_program_menu(menu)
        try:
            option = int(input('Enter option number: '))
            os.system('cls')
            if option == 0:
                try:
                    genre = input('Enter genre: ')
                    result = music_reports.get_albums_by_genre(albums, genre)
                    display.print_albums_list(result)
                except:
                    display.print_command_result('Genre not found!')

            elif option == 1:
                result = music_reports.get_genre_stats(albums)
                print(result)

            elif option == 2:
                result = music_reports.get_longest_album(albums)
                display.print_album_info(result)

            elif option == 3:
                try:
                    genre = input('Enter genre: ')
                    result = music_reports.get_last_oldest_of_genre(
                        albums, genre)
                    display.print_album_info(result)
                except:
                    display.print_command_result('Genre not found!')

            elif option == 4:
                result = music_reports.get_total_albums_length(albums)
                display.print_command_result(str(result))

            elif option == 5:
                display.print_albums_list(albums)
                artist = input('Enter artist name: ')
                album_name = input('Enter album_name: ')
                result = delete_album_by_artist_and_album_name(
                    albums, artist, album_name)
                display.print_albums_list(result)
            else:
                print('Option not found')
        except ValueError:
            print('Enter only number!')