def add_order_to_round(people, drinks, rounds): # open_rounds = round_controller.get_rounds_from_database(True) if len(rounds) != 0: open_round = rounds[-1] if open_round.is_open: printer_aux.print_rounds([open_round]) person_id = ask_person_id(texts.ENTER_PERSON_ID, people) if person_id != 0: printer_aux.print_list(texts.DRINKS, drinks) drink_id = ask_number(texts.ENTER_DRINK_ID, 0, len(drinks)) if drink_id != 0: drink = drinks[drink_id - 1] person = people[person_id - 1] new_order = Order(person, drink) try: new_order = round_controller.add_order_to_round_in_database( open_round, new_order) rounds[-1].orders.append(new_order) print(texts.CREATED_ORDER) except DatabaseError: print(texts.DATABASE_ERROR + texts.ORDER_NOT_ADDED) else: print(texts.NOT_OPEN_ROUND) else: print(texts.NOT_ROUNDS) return rounds
def set_favourite_drink(people, drinks): """ Set the person favourite drink + Parameters: - people: list of people - drinks: list of drinks """ # Get Person ID person_id = ask_person_id(texts.ENTER_PERSON_ID, people) if person_id != 0: printer_aux.print_list(texts.DRINKS, drinks) drink_id = ask_number(texts.ENTER_DRINK_ID, 0, len(drinks)) if drink_id != 0: drink = drinks[drink_id - 1] person_to_save = copy.deepcopy(people[person_id - 1]) person_to_save.set_favourite_drink(drink) try: people_controller.update_user_in_database(person_to_save) people[person_id - 1].set_favourite_drink(drink) print(texts.FAVOURITE_DRINK_UPDATED) except DatabaseError: print(texts.DATABASE_ERROR + texts.FAVUOIRTE_DRINK_NOT_SETTED) return people
def ask_drink_in_list(drinks, text): """ Show the list of the drinks and ask for one id of them + Parameters: - drinks: list of drinks """ printer_aux.print_list(texts.DRINKS, drinks) drink_id = ask_number(text, 0, len(drinks)) return drink_id
def set_favourite_drink(people, drinks): """ Set the person favourite drink + Parameters: - people: list of people - drinks: list of drinks """ # Get Person ID person_id = ask_person_id(texts.ENTER_PERSON_ID, people) if person_id != 0: printer_aux.print_list(texts.DRINKS, drinks) drink_id = ask_number(texts.ENTER_DRINK_ID, 0, len(drinks)) if drink_id != 0: drink = drinks[drink_id - 1] people[person_id - 1].set_favourite_drink(drink) print(texts.FAVOURITE_DRINK_UPDATED) return people
def args_options(arg, people, drinks): """ Manage the events available to add as arguments when launching the project. +Parameters: - arg: The argument received - people: list of people - drinks: list of drinks """ if arg == 'get-people': # Print a list of people printer_aux.print_list(texts.PEOPLE, people) elif arg == 'get-drinks': # Print a list of drinks printer_aux.print_list(texts.DRINKS, drinks) else: # If the received argument is not among those available, # an error message is printed and you exit the program. print(texts.AVAILABLE_ARGUMENTS_OPTIONS) exit()
def ask_sublist_people(people, drinks, new_round): """ Show the list of the people and ask what people want in a new list. + Parameters: - people: list of people - text: text to show in console Return a new people list """ system('clear') printer_aux.print_list(texts.PEOPLE, people) new_people_list = [] identifiers = ask_list_of_numbers(texts.ASK_PEOPLE_IDS, 1, len(people)) for p_id in identifiers: new_people_list.append(people[p_id - 1]) printer_aux.print_list(texts.PEOPLE_WHO_WANT_DRINK, new_people_list) printer_aux.enter_to_continue() return ask_drinks_for_pepole(new_round, new_people_list, drinks)
def create_round(people, drinks): """ Function to create a new round, asking for what people want some drink] and what drink (Asking first if they want them favourite drink) + Parameters: - people: list of people - drinks: list of drinks """ system('clear') new_round = Round() new_round.orders = [] brewer_id = ask_person_id(texts.ASK_BREWER, people) if brewer_id != 0: new_round.brewer = people[brewer_id - 1] people_without_favorite = [] if ask_boolean(texts.ROUND_FAVOURITE_DRINKS): for person in people: if person.favourite_drink: new_round.add_order(person, person.favourite_drink) else: people_without_favorite.append(person) if people_without_favorite: system('clear') print(texts.PEOPLE_WITHOUT_FAVOURITE_DRINK) printer_aux.print_list(texts.PEOPLE, people_without_favorite) printer_aux.enter_to_continue() new_round = ask_drinks_for_pepole(new_round, people_without_favorite, drinks) elif ask_boolean(texts.ALL_PEOPLE_WANT_DRINKS): new_round = ask_drinks_for_pepole(new_round, people, drinks) else: new_round = ask_sublist_people(people, drinks, new_round) new_round.print_round() return new_round
def ask_person_id(text, people): printer_aux.print_list(texts.PEOPLE, people) return ask_number(text, 0, len(people))
def run(): people = [] drinks = [] rounds = [] # Default filepaths drinks_filepath = "briw/resources/drinks.txt" people_filepath = "briw/resources/people.txt" rounds_filepath = "briw/resources/rounds.txt" # Read data from files people = file_functions.read_people_from_file(people_filepath) drinks = file_functions.read_drinks_from_file(drinks_filepath) rounds = file_functions.read_rounds(rounds_filepath) # Check arguments functions.check_args(sys.argv, people, drinks) while True: # Print the available options printer_aux.print_options() minimumOptionNumber = 0 maximumOptionNumber = 9 # Ask for a value, which must be a number, # and repeat the question until the user enters a number. op = functions.ask_number(texts.ENTER_OPTION, minimumOptionNumber, maximumOptionNumber) if op == 1: # Print list of drinks printer_aux.print_list(texts.DRINKS, drinks) elif op == 2: # Print list of users printer_aux.print_list(texts.PEOPLE, people) elif op == 3: # Print list of users and preferences printer_aux.print_users_preferences(people) elif op == 4: # Call the function to follow the steps to add a new drink drinks = functions.add_drink(drinks) elif op == 5: # Call the function to follow the steps to add a new person people = functions.create_new_person(people, drinks) elif op == 6: # Set favourite drink people = functions.set_favourite_drink(people, drinks) elif op == 7: # Create a new round new_round = functions.create_round(people, drinks) if len(new_round.orders) != 0: rounds.append(new_round) elif op == 8: # Print rounds printer_aux.print_rounds(rounds) elif op == 9: # HELP MESSAGE print(texts.HELP_MESSAGE) elif op == 0 or op == None: # Just exit the program functions.goodbye(people, drinks, rounds, people_filepath, drinks_filepath, rounds_filepath) exit() else: # If the number you entered is not in the options, ask for it again print(texts.INCORRECT_OPTION) printer_aux.enter_to_continue()