Exemple #1
0
def user_add_pref(my_list1, my_list2, my_dict):
    """ Appends to the specified dictionary, through user inputs, a chosen element from each list
as a key and value respectively. """
    end_loop = False
    while not end_loop:
        try:
            tab.print_counter_var_table("Preferences", "id_number", "names",
                                        my_list1)
            person_id = num_selection(
                """Here are the available people on our list.
Choose the person whose preference you want to change/add.
Enter their id number please: """)
            if 0 < person_id <= len(my_list1):
                try:
                    name = my_list1[person_id - 1]
                    tab.print_counter_var_table("Available Drink Selection",
                                                "Number", "Drink", my_list2)
                    fav_drink_num = input(
                        f"""Great! What is {name}\'s favourite drink? 
Select only from the available drinks menu. Enter a number: """)
                    if not fav_drink_num or fav_drink_num.isspace():
                        print("You have not entered anything!")
                        try_again()
                    elif fav_drink_num.isnumeric() == True:
                        if 0 < int(fav_drink_num) <= len(my_list2):
                            fav_drink = my_list2[int(fav_drink_num) - 1]
                            print(
                                f"""{fav_drink.capitalize()} will be added as {name.capitalize()}'s favourite drink! """
                            )
                            confirmation = confirm()
                            if confirmation:
                                add_to_dict(my_dict, name, fav_drink)
                            else:
                                print("No changes have been made.")
                                pass
                            end_loop = True
                        else:
                            print("Please enter a valid number.")
                            try_again()
                    else:
                        print(f"Please enter only a number.")
                        try_again()
                except ValueError:
                    print("Not a valid input!")
                    try_again()
            else:
                print("Not a valid id number.")
                try_again()
        except ValueError:
            print("You have not entered a number. Try again.")
            try_again()
    return my_dict
Exemple #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()
Exemple #3
0
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()
Exemple #4
0
 def xprint_round(self):
     val_list = []
     for tup in self.round_list:
         val_list.append(tup[1])
     print_counter_var_table(f"{self.round_id}\'s round: All drinks",
                             "Number", "Drink", val_list)
Exemple #5
0
 def xprint_round_history(self):  #enumerate this
     my_tup_list = []
     for tup in self.round_list:
         my_tup_list.append(f"{tup[0]} added {tup[1]}")
     print_counter_var_table(f"Round History for: {self.round_id}",
                             "Number", "Person : Added Drink", my_tup_list)