def remove_entries(dictionary, dictionary_name, people_dict, drinks_dict): os.system("clear") dictionary_data = ids_to_data(dictionary, people_dict, drinks_dict) draw_table(dictionary_name, dictionary_data, 2) ids = [] for user_id in dictionary.keys(): ids.append(user_id) removed_data = input( f"\nPlease enter the numbers of the people whose {dictionary_name} you would like to REMOVE, " f"separated by commas: ") print() if removed_data.strip() != "" and not removed_data.isalpha(): removed_data = number_cleaner(removed_data) else: return dictionary if isinstance(dictionary, list): for item in removed_data: dictionary.remove(item) elif isinstance(dictionary, dict): data = update_data(dictionary_name, removed_data, dictionary, ids, "remove") return data
def round_menu(menu_options, people_dict, drinks_dict, last_order_dict): round_instance = initialise_round(people_dict) if round_instance == 0: return db.add_data("rounds", "brewer_id", [round_instance.brewer_id]) db.update_data("rounds", "round_id", "active", {db.get_round_id(): 1}) round_instance = round_intro(round_instance, drinks_dict) brewer_drink = list(round_instance.orders.values())[0] db.add_order(round_instance.brewer_id, brewer_drink, db.get_round_id()) while round_instance.active: os.system("clear") orders_dict = ids_to_data(round_instance.orders, people_dict, drinks_dict) draw_table("orders", orders_dict, 2) editing_choice = draw_menu(menu_options) os.system("clear") if editing_choice == 1: round_instance.orders = add_entries(round_instance.orders, "orders", people_dict, drinks_dict) elif editing_choice == 2: round_instance.orders = remove_entries(round_instance.orders, "orders", people_dict, drinks_dict) elif editing_choice == 3: db.update_data("rounds", "brewer_id", "active", {round_instance.brewer_id: 0}) final_order = round_instance.close_round() final_order_data = ids_to_data(final_order, people_dict, drinks_dict) print("The final order is:\n") draw_table("orders", final_order_data, 2) last_order_dict = final_order else: input( "Please enter a number from the options given. Press ENTER to try again." ) return last_order_dict
def initialise_round(people_dict): while True: os.system("clear") ids = draw_table("people", people_dict) brewer_chosen = input('''What number is your name? (If it is not on the list, type X to return to main menu.) Name Number: ''') if brewer_chosen.upper() == "X": return 0 else: brewer_chosen = number_cleaner(brewer_chosen) if len(brewer_chosen) == 1: brewer_index = brewer_chosen[0] - 1 if brewer_index < len(ids) and brewer_index != -1: brewer_id = ids[brewer_index] new_round = Round(people_dict[brewer_id], brewer_id) return new_round else: user_exit = input( '''Please make sure your name is on the list, please exit and add it if it is not. Press ENTER to try again or type X to exit: ''') if user_exit.upper() == "X": return 0 else: user_exit = input( '''Please only enter one number. Do not include words or special characters (!@£$%%^&*). Press ENTER to go back and try again, or type X to exit: ''') if user_exit.upper() == "X": return 0
def round_intro(round_instance, drinks_dict): while True: os.system("clear") ids = draw_table("drinks", drinks_dict) brewer_drink_id = round_instance.welcome(ids, drinks_dict) if brewer_drink_id == -1: continue elif brewer_drink_id == 0: return round_instance else: round_instance.add_order(round_instance.brewer_id, brewer_drink_id) return round_instance
def remove_data(data_name, data): os.system("clear") ids = draw_table(data_name, data) removed_data = input( f"\nPlease enter the number of the {data_name} you would like to REMOVE, separated by commas: " ) print() removed_data = number_cleaner(removed_data) if isinstance(data, list): for item in removed_data: if item < len(data): removed_data.remove(item) elif isinstance(data, dict): data = update_data(data_name, removed_data, data, ids, mode="remove") return data
def add_data(data_name, data): os.system("clear") ids = draw_table(data_name, data) added_data = input( f"\nPlease enter the name of the {data_name} you would like to ADD, separated by commas: " ) print() added_data = name_cleaner(added_data) if added_data == "": return data if isinstance(data, list): data += added_data elif isinstance(data, dict): data = update_data(data_name, added_data, data, ids, mode="add") return data
def add_entry_menu(data_name, dictionary): ids = draw_table(data_name, dictionary) added_data = input( f"\nPlease enter the numbers of the {data_name} you would like to ADD/CHANGE, separated by commas: " ) print() added_data = number_cleaner(added_data) invalid_data = [] for item in added_data: if item > len(ids): invalid_data.append(item) for invalid_entry in invalid_data: added_data.remove(invalid_entry) input( f"Entry out of range. Ignored the following entry: {invalid_entry}\n\nPress ENTER to continue.\n" ) os.system("clear") return ids, added_data
def start_app(): try: user_exit = False menu_options = { 1: "List of people", 2: "List of drinks", 3: "List of people and drinks", 4: "Edit people", 5: "Edit drinks", 6: "List of preferences", 7: "Edit preferences", 8: "Start round", 9: "View last round", 10: "Exit" } edit_list_options = {1: "ADD", 2: "REMOVE"} edit_preferences_options = {1: "ADD/CHANGE", 2: "REMOVE"} edit_round_options = {1: "ADD/CHANGE", 2: "REMOVE", 3: "COMPLETE"} people_dict = table_to_dict("person") drinks_dict = table_to_dict("drink") preferences_dict = table_to_dict("preference") last_order_dict = table_to_dict("orders") while not user_exit: os.system("clear") user_selection = draw_menu(menu_options, draw_brIW()) user_selection = int(user_selection) if user_selection > len(menu_options) or user_selection <= 0: input( "\nPlease only enter a number from the options provided. Press 'Enter' to try again." ) continue elif user_selection == 1: people_dict = table_to_dict("person") os.system("clear") draw_table("people", people_dict) elif user_selection == 2: drinks_dict = table_to_dict("drink") os.system("clear") draw_table("drinks", drinks_dict) elif user_selection == 3: people_dict = table_to_dict("person") drinks_dict = table_to_dict("drink") os.system("clear") draw_table("people and drinks", [people_dict, drinks_dict], 2) elif user_selection == 4: os.system("clear") draw_table("people", people_dict) editing_choice = edit_menu(edit_list_options) if editing_choice == "ADD": people_dict = add_data("person", people_dict) elif editing_choice == "REMOVE": people_dict = remove_data("person", people_dict) elif user_selection == 5: os.system("clear") draw_table("drinks", drinks_dict) editing_choice = edit_menu(edit_list_options) if editing_choice == "ADD": drinks_dict = add_data("drink", drinks_dict) elif editing_choice == "REMOVE": drinks_dict = remove_data("drink", drinks_dict) elif user_selection == 6: preferences_dict = table_to_dict("preference") os.system("clear") preferences_data = ids_to_data(preferences_dict, people_dict, drinks_dict) draw_table("preferences", preferences_data, 2) elif user_selection == 7: os.system("clear") preferences_data = ids_to_data(preferences_dict, people_dict, drinks_dict) draw_table("preferences", preferences_data, 2) editing_choice = edit_menu(edit_preferences_options) if editing_choice == "ADD/CHANGE": preferences_dict = add_entries(preferences_dict, "preferences", people_dict, drinks_dict) elif editing_choice == "REMOVE": preferences_dict = remove_entries(preferences_dict, "preferences", people_dict, drinks_dict) elif user_selection == 8: os.system("clear") last_order_dict = round_menu(edit_round_options, people_dict, drinks_dict, last_order_dict) elif user_selection == 9: last_order_dict = table_to_dict("orders") os.system("clear") last_order_data = ids_to_data(last_order_dict, people_dict, drinks_dict) draw_table("orders", last_order_data, 2) elif user_selection == 10: exit_screen() user_exit = True if user_selection != 10: input("Press ENTER to return to the Main Menu.") except Exception as err: print("Error") print(err)