def get_albums():
    user_input = input(
        "Please provide text file name to import data from it: ")
    if not user_input:
        albums = file_handling.import_data()
    else:
        albums = file_handling.import_data(user_input)
    return albums
Exemple #2
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 = ['Display albums list',
            'Delete album',
            'Add album',
            'Get albums by genre',
            'Display oldest album',
            'Display oldest album in selected genre'
            'Show genre statistics',
            'Display longest album',
            'Display total albums lenght'
            ]

    albums = file_handling.import_data()

    while True:
        display.print_command_result('Welcome in albums database app')
        display.print_command_result('Select an option')
        display.print_program_menu(menu)
def main():
    # importuje plik i zapisuje w lokalnej dla tego modułu liście
    albums_data = file_handling.import_data("albums_data.txt")
    working = True
    check = True
    text = ""
    # loopa zeby menu było wyświetlane non stop, nawet jesli ValueError to znaczy jesli input
    # nie bedzie int. text jest po to zeby wyswietlac okreslony komunikat w dowolnie wybranym miejscu
    # w przypadku dobrze wybranej opcji zamieniam text na pusty string zeby komunika nie byl wysiwetlany
    while working and check:
        try:
            display.print_program_menu([
                "Show table", "Delete album", "Display oldest album",
                "Get albums by genre", "What is the oldest album by genre",
                "For arrow keys navigation"
            ], text)
            choice = int(input("What is your choice?:"))
            if choice == 1:
                display.print_albums_list(albums_data)
                display.pause()
                text = ""
            elif choice == 2:
                display.print_albums_list(albums_data)
                artist = input("What is name of artist you want to delete: ")
                album_name = input(
                    "What is name of album you want to delete: ")
                delete_album_by_artist_and_album_name(albums_data, artist,
                                                      album_name)
                text = ""
            elif choice == 3:
                display.print_command_result(
                    music_reports.get_last_oldest(albums_data))
                text = ""
            elif choice == 4:
                try:
                    genre = input("What is the genre?: ")
                    display.print_albums_list(
                        music_reports.get_albums_by_genre(albums_data, genre))
                    display.pause()
                    text = ""
                except (ValueError, IndexError, TypeError):
                    text = "\033[41;33mNo such genre\33[m"
            elif choice == 5:
                try:
                    genre = input("What is the genre?: ")
                    display.print_command_result(
                        music_reports.get_last_oldest_of_genre(
                            albums_data, genre))
                    text = ""
                except (ValueError, IndexError, TypeError):
                    text = "\033[41;33mNo such genre\33[m"
            elif choice == 6:
                arow_nawigation_menu()
            elif choice == 0:
                display.clear()
                working = False
        except ValueError:
            text = "\033[41;33mGive proper number\33[m"
Exemple #4
0
def choice_word():
    """This function gets data from file
    chooses by random word
    Returns:
        word as string
    """
    capitals = file_handling.import_data(filename)
    choice = random.choice(capitals)
    word = ("".join(choice)).lower()
    return word
Exemple #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
    """
    os.system('clear')
    menu_options = [
        'Print albums list', 'Get_albums_by_genre', 'Get_longest_album',
        'Get_total_albums_length'
    ]
    display.print_program_menu(menu_options)
    albums = file_handling.import_data()
    menu_option_choose(albums)
Exemple #6
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")
Exemple #7
0
    def test_import_data(self):
        actual = import_data(self.test_filename)

        self.assertListEqual(actual, self.albums)
Exemple #8
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.")
Exemple #9
0
"""
The main program should use functions from music_reports and display modules
"""
import file_handling
import music_reports
import display
filename = 'albums_data.txt'
albums = file_handling.import_data(filename)


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


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
def arow_nawigation_menu():
    albums_data = file_handling.import_data("albums_data.txt")
    working = True
    check = False
    text = ""
    menu_index = 0
    menu_lenght = 7
    # while not check and working:"\33[46;37m","\33[m"
    while working and not check:
        arrow_choice = []
        menu_index = ((7000 - len(arrow_up) + len(arrow_down)) % menu_lenght
                      )  #7k gdyby ktos chcial naciska up arrow
        printing_addons = [
            ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""]
        ]  #lista z brakujacym elementem ktora bedzie dodrukowywana do menu
        printing_addons.insert(
            menu_index, ["==>>", "<<=="]
        )  # brakujacy element o konkretnym indeksie ktory bedzie zmieniał kolor czcionki
        display.print_program_menu_arrow_nawigation([
            "             Show table              ",
            "            Delete album             ",
            "         Display oldest album        ",
            "          Get albums by genre        ",
            "  What is the oldest album by genre  ",
            "      For number keys navigation     ",
            "                Exit                 "
        ], text, menu_index, printing_addons)
        arrow_sensing(arrow_choice)
        if menu_index == 0 and len(arrow_choice) > 0:
            display.print_albums_list(albums_data)
            display.pause()
            text = ""
        elif menu_index == 1 and len(arrow_choice) > 0:
            display.print_albums_list(albums_data)
            artist = input("What is name of artist you want to delete: ")
            album_name = input("What is name of album you want to delete: ")
            delete_album_by_artist_and_album_name(albums_data, artist,
                                                  album_name)
            text = ""
        elif menu_index == 2 and len(arrow_choice) > 0:
            display.print_command_result(
                music_reports.get_last_oldest(albums_data))
            text = ""
        elif menu_index == 3 and len(arrow_choice) > 0:
            try:
                genre = input("What is the genre?: ")
                display.print_albums_list(
                    music_reports.get_albums_by_genre(albums_data, genre))
                display.pause()
                text = ""
            except (ValueError, IndexError, TypeError):
                text = "\033[41;33mNo such genre\33[m"
        elif menu_index == 4 and len(arrow_choice) > 0:
            try:
                genre = input("What is the genre?: ")
                display.print_command_result(
                    music_reports.get_last_oldest_of_genre(albums_data, genre))
                text = ""
            except (ValueError, IndexError, TypeError):
                text = "\033[41;33mNo such genre\33[m"
        elif menu_index == 5 and len(arrow_choice) > 0:
            check = True
        elif menu_index == 6 and len(arrow_choice) > 0:
            display.clear()
            exit()
Exemple #11
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!')
"""
The main program should use functions from music_reports and display modules
"""
from file_handling import import_data,export_data
from music_reports import get_albums_by_genre, get_genre_stats,get_longest_album,get_last_oldest,get_last_oldest_of_genre,get_album_by_year,get_total_albums_length
from display import print_albums_list,print_command_result,print_program_menu,print_album_info

MENU = ['display all teh albums','get_albums_by_genre', 'get_genre_stats','get_longest_album','get_last_oldest','get_last_oldest_of_genre','get_total_albums_length','get album by year']
file_albums = import_data()
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 main():
    """
def get_file():
    return file_handling.import_data()

def display_menu():
    menu_commands = ['Quit',
                     'Albums by genre',
                     'Longest album',
                     'Total album length',
                     'Sort by duration',
                     'Delete by genre']
    ui.print_program_menu(menu_commands)


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


albums = file_handling.import_data('albums_data.txt')
while True:
    display_menu()
    choose_options_menu(albums)

if __name__ == '__main__':
    main()
import os
import file_handling
import display
import sys

ARTIST = 0
ALBUM = 1
YEAR = 2
GENRE = 3
DURATION = 4
#---------------------------------------------------------------
#VARIABLES FOR SPECIAL FUNCTIONS

table = file_handling.import_data()
title_list = ['ARTIST', 'ALBUM', 'YEAR', 'GENRE', 'DURATION']

#-------------------------------------------------------------
#MENU FUNCTIONS


#Shows data in a neat table
def show_music_library():
    display.print_table(table, title_list)


def add_album_to_library():
    pass


#FUNCTION RETURNS LIST OF ALBUMS FROM GIVEN GENRE IN SEPARATE LINES
def get_albums_by_genre():