コード例 #1
0
def user_remove_pref(my_dict):
    """Removes key:value pair, specified through user input, from specified dictionary."""
    tab.print_table_dict("Preferences", "names", "favourite drink", my_dict)
    try:
        person_name = input("""Here are the available people on our list.
Choose the person whose preference you want to remove.
Enter their name please: """)
        if not person_name or person_name.isspace():
            print("You have not entered in anything!")
        elif person_name.capitalize() not in my_dict.keys():
            print(
                f"{person_name.capiltalize()} does not have a preference already."
            )
        elif any(num in person_name for num in "01234567890"):
            print(f"No numbers can be included. Try again.")
        elif person_name.capitalize() in my_dict.keys():
            print(
                f"""{person_name.capitalize()}'s drink preference will be removed."""
            )
            confirmation = confirm()
            if confirmation:
                remove_from_dict(my_dict, person_name)
            else:
                print("No changes have been made.")
                pass
    except ValueError:
        print("Not a valid input!")
        input("Enter any key to try again: ")
    return my_dict
コード例 #2
0
def user_input():
    "User input interface for menu."
    #loading data from database
    sql.load_data_from_sql()
    people_list = sql.people_list
    drinks_list = sql.drinks_list

    #loading from CSV files using ClASS FUNCTIONS
    drinks_file = File_Store(drinks_filepath)
    #drinks_list = drinks_file.load_into_list()

    people_file = File_Store(people_filepath)
    #people_list = people_file.load_into_list()

    preferences_file = File_store_dict(preferences_filepath)
    preferences = preferences_file.load_into_dict()

    menu_options_file = File_Store(menu_options_filepath)
    menu_options_list = menu_options_file.load_into_list()

    round_file = rd.File_store_round(round_filepath)
    all_rounds_list = round_file.load_file_to_dict_round()

    end_loop = False
    while not end_loop:
        try:
            os.system("clear")
            print_counter_var_table("BrewCo Options Menu :)", "number",
                                    "options", menu_options_list)
            print(" Welcome to BrewCo!")
            choice = num_selection("Select an option by entering a number: ")
            if choice == 2:
                os.system("clear")
                print_table_list("Users", people_list)
                hold()
            elif choice == 3:
                os.system("clear")
                print_table_list("Drinks", drinks_list)
                hold()
            elif choice == 6:
                os.system("clear")
                print("Add a new User?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    print_table_list("Users", people_list)
                    person = input(
                        """Here are the users currently in our database.
Please use an unique name. Enter a new user's name: """)
                    confirmation = confirm()
                    if confirmation:
                        people_list = add_list_element(people_list, person)
                    else:
                        print("No changes have been made.")
                        pass
                else:
                    pass
                hold()
            elif choice == 10:
                os.system("clear")
                print("Remove an User?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    print_counter_var_table("User database", "id", "name",
                                            people_list)
                    person_id = num_selection(
                        """Here are the people in our database.
Note: Both the user and their preference (if one exists) will be removed.
Enter user's I.D. number to remove them: """)
                    if 0 < person_id <= len(people_list):
                        name = people_list[person_id - 1]
                        print(f"{name} will be removed from the database.")
                        confirmation = confirm()
                        if confirmation:
                            people_list = remove_list_element(
                                people_list, name)
                            if name in preferences.keys():
                                preferences.pop(name)
                            else:
                                pass
                        else:
                            print("No changes have been made.")
                            pass
                    else:
                        print("Please enter a valid number. Try again.")
                else:
                    pass
                hold()
            elif choice == 7:
                os.system("clear")
                print("Add a new drink?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    print_table_list("Drink Selection", drinks_list)
                    drink = input(
                        """Here is the currently available drinks selection.
Enter a new drink option: """)
                    confirmation = confirm()
                    if confirmation:
                        drinks_list = add_list_element(drinks_list, drink)
                        for key, value in preferences.items():
                            if drink + " (discontinued)" == value:
                                preferences[key] = drink
                            else:
                                pass
                    else:
                        print("No changes have been made.")
                        pass
                else:
                    pass
                hold()
            elif choice == 11:
                os.system("clear")
                print("Remove a drink?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    print_counter_var_table("Available Drinks Selection",
                                            "i.d.", "drink", drinks_list)
                    drink_id = num_selection(
                        """Here are all the drinks available currently.
Enter the drink's I.D. number to remove it: """)
                    if 0 < drink_id <= len(drinks_list):
                        drink_name = drinks_list[drink_id - 1]
                        print(
                            f"{drink_name} will be removed from the database and no longer available."
                        )
                        confirmation = confirm()
                        if confirmation:
                            drinks_list = remove_list_element(
                                drinks_list, drink_name)
                            for name, drink in preferences.items():
                                if drink_name == drink:
                                    preferences[
                                        name] = drink + " (discontinued)"
                                else:
                                    pass
                        else:
                            print("No changes have been made.")
                            pass
                    else:
                        print("Please enter a valid number. Try again.")
                else:
                    pass
                    pass
                hold()
            elif choice == 8:
                os.system("clear")
                print("Add a new User preference?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    preferences = user_add_pref(people_list, drinks_list,
                                                preferences)
                else:
                    pass
                hold()
            elif choice == 12:
                os.system("clear")
                print("Remove an User preference?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    user_remove_pref(preferences)
                else:
                    pass
                hold()
            elif choice == 4:
                os.system("clear")
                print_table_dict("User Preferences", "name", "favourite drink",
                                 preferences)
                hold()
            elif choice == 5:
                os.system("clear")
                rd.print_all_rounds_table(all_rounds_list, "All Rounds",
                                          "Round ID", "Owner", "Brewer",
                                          "Active Status")
                hold()
            elif choice == 9:
                os.system("clear")
                print("Begin a new round?")
                confirmation = confirm()
                if confirmation:
                    all_rounds_list = rd.round_user_input(people_list)
                else:
                    pass
                hold()
            elif choice == 1:
                drinks_file.save_list_to_file(drinks_list)
                people_file.save_list_to_file(people_list)
                preferences_file.save_dict_to_file(preferences)
                round_file.save_all_rounds_to_file(all_rounds_list)

                drinks_file = File_Store(drinks_filepath)
                people_file = File_Store(people_filepath)
                drinks_file.save_list_to_file(drinks_list)
                people_file.save_list_to_file(people_list)
                sql.load_from_csv_to_sql()

                os.system("clear")
                print(f"Thanks for using the app!{cat}")
                end_loop = True  #while loop termination condition or exit()
            elif choice > len(menu_options_list) or choice < 1:
                print("Not a valid number. Try again")
                hold()
        except ValueError:
            print("Please enter a number. Try again")
            hold()
コード例 #3
0
ファイル: drinkapp.py プロジェクト: YVass1/BrewApp
def user_input():
    "User input interface for menu."
    
    end_loop =  False 
    while not end_loop:
        try :
            #loading data from database
            people_list, drinks_list, preferences, all_rounds_object_list = db_persist.load_data_from_sql()
            menu_options_file = File_Store_list(menu_options_filepath)
            menu_options_list = menu_options_file.load_into_list()

            os.system("clear")
            print_menu_options( menu_options_list)
            print("Welcome to BrewCo!")
            choice = num_selection("Select an option by entering a number: ")
            if choice == 2:
                os.system("clear")
                print_table_list("Users", people_list)
                hold()
            elif choice == 3:
                os.system("clear")
                print_table_list("Drinks", drinks_list)
                hold()
            elif choice ==7:
                os.system("clear")
                print("Add a new User?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    print_table_list("Users", people_list)
                    person = input("""Here are the users currently in our database.
Please use an unique name. Enter a new user's name: """).capitalize()
                    confirmation = confirm()
                    if confirmation:
                        #people_list = add_list_element(people_list, person)
                        com.add_person(person)
                        print(f"{person} has been added as an user!")
                    else:
                        print("No changes have been made.")
                        pass
                else:
                    pass
                hold()
            elif choice == 12:
                os.system("clear")
                print("Remove an User?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    print_counter_var_table("User database","id","name", people_list)
                    person_id = num_selection("""Here are the people in our database.
Note: Both the user and their preference (if one exists) will be removed.
Enter user's I.D. number to remove them: """)
                    if 0 < person_id <= len(people_list):
                        name = people_list[person_id-1]
                        print(f"{name} will be removed from the database.")
                        confirmation = confirm()
                        if confirmation:
                            com.remove_person(name)
                        else:
                            print("No changes have been made.")
                            pass
                    else:
                        print("Please enter a valid number. Try again.")
                else:
                    pass
                hold()
            elif choice ==8:
                os.system("clear")
                print("Add a new drink?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    print_table_list("Drink Selection", drinks_list)
                    drink = input("""Here is the currently available drinks selection.
Enter a new drink option: """).capitalize()
                    confirmation = confirm()
                    if confirmation:
                       com.add_drink(drink)
                    else:
                        print("No changes have been made.")
                        pass
                else:
                    pass
                hold()
            elif choice == 13:
                os.system("clear")
                print("Remove a drink?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    print_counter_var_table("Available Drinks Selection", "i.d.", "drink",drinks_list)
                    drink_id = num_selection("""Here are all the drinks available currently.
Enter the drink's I.D. number to remove it: """)
                    if 0 < drink_id <= len(drinks_list):
                        drink_name = drinks_list[drink_id-1]
                        print(f"{drink_name} will be removed from the database and no longer available.")
                        confirmation = confirm()
                        if confirmation:
                            com.remove_drink(drink_name)
                            print(f'{drink_name} has been removed from the drinks selection!')
                        else:
                            print("No changes have been made.")
                            pass
                    else:
                        print("Please enter a valid number. Try again.")
                else:
                    pass
                    pass
                hold()
            elif choice ==9:
                os.system("clear")
                print("Add a new User preference?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    com.user_add_pref(people_list, drinks_list, preferences)
                else:
                    pass
                hold()
            elif choice == 14:
                os.system("clear")
                print("Remove an User preference?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    com.user_remove_pref(preferences)
                else:
                    pass
                hold()
            elif choice == 4:
                os.system("clear")
                print_table_dict("User Preferences", "name", "favourite drink", preferences)
                hold()
            elif choice == 5:
                os.system("clear")
                longest_col1 = tab.long_col1(all_rounds_object_list)
                longest_col2 = tab.long_col2(all_rounds_object_list)
                longest_col3 = tab.long_col3(all_rounds_object_list)
                longest_col4 = tab.long_col4(all_rounds_object_list)
                width = tab.all_rounds_table_width("All Rounds","Round ID","Owner","Brewer","Active Status", longest_col1, longest_col2, longest_col3, longest_col4)
                tab.print_all_rounds_table(all_rounds_object_list,"All Rounds","Round ID","Owner","Brewer","Active Status", width, longest_col1, longest_col2, longest_col3, longest_col4)
                hold()
            elif choice == 10:
                os.system("clear")
                print("Begin a new round?")
                confirmation = confirm()
                if confirmation:
                    com.round_user_input(people_list)
                else:
                    pass
                hold()
            elif choice ==6:
                os.system("clear")
                print("See a round's order history?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    longest_col1 = tab.long_col1(all_rounds_object_list)
                    longest_col2 = tab.long_col2(all_rounds_object_list)
                    longest_col3 = tab.long_col3(all_rounds_object_list)
                    longest_col4 = tab.long_col4(all_rounds_object_list)
                    width = tab.all_rounds_table_width("All Rounds","Round ID","Owner","Brewer","Active Status", longest_col1, longest_col2, longest_col3, longest_col4)
                    tab.print_all_rounds_table(all_rounds_object_list,"All Rounds","Round ID","Owner","Brewer","Active Status", width, longest_col1, longest_col2, longest_col3, longest_col4)
                    com.user_see_round_history( all_rounds_object_list)
                else:
                    pass
                hold()
            elif choice == 11:
                os.system("clear")
                print("Add an order to a round?")
                confirmation = confirm()
                if confirmation:
                    longest_col1 = tab.long_col1(all_rounds_object_list)
                    longest_col2 = tab.long_col2(all_rounds_object_list)
                    longest_col3 = tab.long_col3(all_rounds_object_list)
                    longest_col4 = tab.long_col4(all_rounds_object_list)
                    width = tab.all_rounds_table_width("All Rounds","Round ID","Owner","Brewer","Active Status", longest_col1, longest_col2, longest_col3, longest_col4)
                    tab.print_all_rounds_table(all_rounds_object_list,"All Rounds","Round ID","Owner","Brewer","Active Status", width, longest_col1, longest_col2, longest_col3, longest_col4)
                    com.user_add_order_to_round(all_rounds_object_list, people_list, drinks_list)
                else:
                    pass
                hold()
            elif choice == 15:
                os.system("clear")
                print("Remove a round?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    longest_col1 = tab.long_col1(all_rounds_object_list)
                    longest_col2 = tab.long_col2(all_rounds_object_list)
                    longest_col3 = tab.long_col3(all_rounds_object_list)
                    longest_col4 = tab.long_col4(all_rounds_object_list)
                    width = tab.all_rounds_table_width("All Rounds","Round ID","Owner","Brewer","Active Status", longest_col1, longest_col2, longest_col3, longest_col4)
                    tab.print_all_rounds_table(all_rounds_object_list,"All Rounds","Round ID","Owner","Brewer","Active Status", width, longest_col1, longest_col2, longest_col3, longest_col4)
                    com.user_remove_round(all_rounds_object_list)
                else:
                    pass
                hold()
            elif choice ==16:
                os.system("clear")
                print("Remove an order from round?")
                confirmation = confirm()
                if confirmation:
                    os.system("clear")
                    longest_col1 = tab.long_col1(all_rounds_object_list)
                    longest_col2 = tab.long_col2(all_rounds_object_list)
                    longest_col3 = tab.long_col3(all_rounds_object_list)
                    longest_col4 = tab.long_col4(all_rounds_object_list)
                    width = tab.all_rounds_table_width("All Rounds","Round ID","Owner","Brewer","Active Status", longest_col1, longest_col2, longest_col3, longest_col4)
                    tab.print_all_rounds_table(all_rounds_object_list,"All Rounds","Round ID","Owner","Brewer","Active Status", width, longest_col1, longest_col2, longest_col3, longest_col4)
                    com.remove_order_from_round(all_rounds_object_list)                
                else:
                    pass
                hold()
            elif choice == 1:
                os.system("clear")
                print(f"Thanks for using the app!{cat}")
                end_loop = True #while loop termination condition or exit()
            elif choice > len(menu_options_list) or choice < 1: 
                print("Not a valid number. Try again")
                hold()
        except ValueError:
            print("Please enter a number. Try again")
            hold()