def comm_update(table, title_list): temp_list = [] id_ = ui.get_inputs(["id: "], "Give me an id: ") new_line = [] new_line.append(id_[0]) for i in range(len(title_list)): title_list[0] = title_list[i] temp_list.append(ui.get_inputs(title_list, "Give me a data!")) new_line.append(temp_list[i][0]) for i in range(len(table)): if table[i][0] == id_[0]: table[i] = new_line
def common_add(table, title_list): new_add = [] new_id = generate_random(table) new_add = ui.get_inputs(title_list, "Give me an") new_add.insert(0, new_id) table.append(new_add) return table
def comm_add(table, title_list): temp_list = [] new_line = [generate_random(table)] for i in range(len(title_list)): title_list[0] = title_list[i] temp_list.append(ui.get_inputs(title_list, "Give me a data!")) new_line.append(temp_list[i][0]) table.append(new_line) return table
def common_update(table, title_list, id_): new_line = [] new_line.append(id_) new_line += ui.get_inputs(title_list, "Update the information") for i in table: if i[0] == id_: table.remove(i) table.append(new_line) return table ui.print_error_message("This ID doesn't exist.") return table
def update(table, list_labels, id_): new_data = [] updated_id = 0 inputs = ui.get_inputs(list_labels, "") table_len = len(table) inputs.insert(0, id_) for id in range(table_len): if table[id][0] == inputs[0]: table[id] = inputs break return table
def ask_for_data_to_add(table, list_of_titles): code = generate_random(table) all_data = [code] for title in list_of_titles: to_all_data = str("".join(ui.get_inputs(["Please enter a " + str(title) + ": "], ""))) all_data.append(to_all_data) return all_data
def ask_for_data_and_update(table, id_, list_of_titles): ui.print_menu("What do you want to update?", list_of_titles, "Back") number_given = False while not number_given: try: to_update = int(ui.get_inputs(["Please enter a number: "], "")[0]) if to_update > (-1) and to_update < 5: number_given = True else: number_given = False except: number_given = False if to_update != 0: update_to = str(ui.get_inputs(["Update data to: "], "")[0]) for all_info in table: id_to_observe = "".join(all_info[0]) if id_to_observe == id_: all_info[to_update] = update_to return table else: return table
def choose(): inputs = ui.get_inputs("Please enter a number: ", "") option = inputs[0] if option == "1": student.start_module() elif option == "2": company.start_module() elif option == "3": position.start_module() elif option == "4": application.start_module() elif option == "0": quit() else: raise KeyError("There is no such option!")
def update(table, id_): for sublist in table: try: if id_[0] in sublist: inputs = ui.get_inputs([ "Full name: ", "E-mail address: ", "Subscription (1/0): " ], "") for item in range(len(sublist)): sublist[item] = inputs[item] except KeyError as err: ui.print_error_message(str(err)) data_manager.write_table_to_file("crm/customers.csv", table) return table
def start_module(): """ Starts this module and displays its menu. User can access default special features from here. User can go back to main menu from here. Returns: None """ while True: my_table = data_manager.get_table_from_file("accounting/items.csv") menu = ["Show table", "Add to table", "Remove from table", "Update data"] ui.print_menu("Accounting manager", menu, "Exit menu") inputs = ui.get_inputs(["Please choose a number: "], "") option = inputs[0] if option == "1": show_table(my_table) elif option == "2": add(my_table) elif option == "3": item_id = ui.get_inputs(["Which ID would you like to remove? "], "") remove(my_table, item_id)
def choose_menu_option(): inputs = ui.get_inputs(["Please enter a number: "], "") option = str(inputs[0]) if option == "1": recipes.start_module() elif option == "2": groceries.start_module() elif option == "3": week_menu.start_module() elif option == "4": week_menu.random_menu() elif option == "0": sys.exit(0) else: raise KeyError("There is no such option.")
def add(table): """ Asks user for input and adds it into the table. Args: table (list): table to add new record to Returns: list: Table with a new record """ title_input = "Please enter the product data: " inputs = ui.get_inputs([x + ": " for x in list_labels[1:]], title_input) inputs.insert(0, common.generate_random(table)) table.append(inputs) return table
def update(table, id_): for lists in table: if id_[0] == lists[0]: new_list = ui.get_inputs( ['name', 'manufacturer', 'purchase date', 'durability'], "Please provide your information") lists[1] = new_list[0] lists[2] = new_list[1] lists[3] = new_list[2] lists[4] = new_list[3] data_manager.write_table_to_file("inventory/inventory.csv", table) return table
def go_back_in_menu(): while True: print("") go_back_input = ui.get_inputs( ["Enter '0' to go back: "], "" ) try: if go_back_input == "0": break else: raise KeyError("There is no such option") except KeyError as err: ui.print_error_message(str(err))
def get_items_sold_between_wrapper(): table = data_manager.get_table_from_file(FILE_NAME) # check if input is intiger try: dates = ui.get_inputs([ 'Month from :', 'Day from :', 'Year from :', 'Month to :', 'Day to :', 'Year to :' ], 'Enter the filtering dates. First the start date, later the end date: ' ) check = [int(inputs) for inputs in dates] get_items_sold_between(table, *check) except: ui.print_error_message( "Value Error. Please provide a correct date format") get_items_sold_between_wrapper()
def add(table): """ Asks user for input and adds it into the table. Args: table: table to add new record to Returns: Table with a new record """ new_customer = ui.get_inputs(['Name', 'E-mail', 'Newsletter subscription'], 'Adding new customer to data') new_customer.insert(0, common.generate_random(table)) new_customer.insert(0, str(len(table))) table.append(new_customer) return table
def start_module(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ options = [ "show table", "add", "remove", "Update", "Get oldest person", "get person closest to average" ] table = data_manager.get_table_from_file("hr/persons.csv") while True: ui.print_menu("Human resources", options, "Main menu") inputs = ui.get_inputs("Please enter a number:", "") option = inputs[0] if option == "1": show_table(table) elif option == "2": table = add(table) #data_manager.write_table_to_file(table, "hr/persons.csv") elif option == "3": userinput = ui.get_inputs("Enter the ID you want to remove: ", "") table = remove(table, userinput) elif option == "4": userinput_id = ui.get_inputs("Enter the ID you want to update: ", "") update(table, userinput_id) elif option == "5": get_oldest_person(table) elif option == "6": get_persons_closest_to_average(table) elif option == "0": break
def add(table, id_): """ Asks user for input and adds it into the table. Args: table (list): table to add new record to Returns: list: Table with a new record """ datauser = ui.get_inputs(['input your name ', 'choose your hire year'], "Please provide your personal information") table.append(id_, datauser[0], datauser(int[1])) return table
def update(table, id_): """ Updates specified record in the table. Ask users for new data. Args: table (list): list in which record should be updated id_ (str): id of a record to update Returns: list: table with updated record """ for i in table: if i[0] == id_: i[1] = ui.get_inputs(["What should i update the titel to: "], "") i[2] = ui.get_inputs( ["What should I update the manufacturer to? "], "") i[3] = ui.get_inputs( ["What should I update the year of purchase to? "], "") i[4] = ui.get_inputs( ["What should I update the durability time in year/s? "], "") data_manager.write_table_to_file("inventory/inventory.csv", table) return table
def start_module(): while True: datas = data_manager.get_table_from_file("accounting/items.csv") options = ["Display table", "Add", "Remove", "Update", "Highest profit year", "Average profit in a given year"] ui.print_menu("\nAccounting Menu", options, "Main menu") inputs = ui.get_inputs(["Please, choose an option: "], "") option = inputs[0] if option == "1": os.system("clear") show_table(datas) elif option == "2": os.system("clear") add(datas) write_to_file(datas) elif option == "3": os.system("clear") given_id = ui.get_inputs(["Please, enter an ID to remove the line: "], "") remove(datas, given_id) write_to_file(datas) elif option == "4": os.system("clear") update_id = ui.get_inputs(["Please, enter an ID to update the line: "], "") update(datas, update_id) write_to_file(datas) elif option == "5": os.system("clear") ui.print_result(which_year_max(datas), "The year having the highest profit:") elif option == "6": os.system("clear") year_list = ui.get_inputs(["Year: "], "Please, add the year to get its average profit!") ui.print_result(avg_amount(datas, int(year_list[0])), "The avarage profit of " + year_list[0] + ":") elif option == "0": os.system("clear") break else: ui.print_error_message("There is no such option.")
def add(table): """ Asks user for input and adds it into the table. Args: table: table to add new record to Returns: Table with a new record """ user_input = ui.get_inputs(['month', 'day', 'year', 'type', ' amount'],"Please provide information") while common.is_number(user_input[0]) is False or common.is_number(user_input[2]) is False or common.is_number(user_input[3]) is False or common.is_number(user_input[4]) is False: ui.print_error_message('Error: Price and Stock value must be numbers') user_input = ui.get_inputs(['month', 'day', 'year', 'type', 'amount'],"Please provide information") continue new_id = common.generate_random(table) new_record = [new_id] + user_input table += [new_record] data_manager.write_table_to_file('accounting/items.csv', table) return table # your code '''user_input = ui.get_inputs(['month', 'day', 'year', 'type', 'amount'], "Please provide your personal information")
def get_subscribed_emails(table): """ Question: Which customers has subscribed to the newsletter? Args: table (list): data table to work on Returns: list: list of strings (where a string is like "email;name") """ # your code subscribed_str = "" subscribed_list = [] for i in range(len(table)): if table[i][3] == "1" and i != (len(table) - 1): subscribed_str = subscribed_str + table[i][2] + ";" + table[i][ 1] + "," elif table[i][3] == "1" and i == (len(table) - 1): subscribed_str = subscribed_str + table[i][2] + ";" + table[i][1] subscribed_list = subscribed_str.split(",") subscribed_list.remove('') ui.get_inputs("Press Enter to to advance!", "") return subscribed_list
def update(table, id_): """ Updates specified record in the table. Ask users for new data. Args: table (list): list in which record should be updated id_ (str): id of a record to update Returns: list: table with updated record """ # your code userinput_name = ui.get_inputs("Name: ", "") userinput_email = ui.get_inputs("Email: ", "") userinput_subbed = ui.get_inputs("Subscribed? (0/1): ", "") for sublist in table: if id_ in sublist: sublist[0] = common.generate_random(table) sublist[1] = userinput_name sublist[2] = userinput_email sublist[3] = userinput_subbed return table
def add(table): """ Asks user for input and adds it into the table. Args: table (list): table to add new record to Returns: list: Table with a new record """ store_data = ["Title: ", "Manufacturer: ", "Price: ", "In Stock: "] inputs = ui.get_inputs(store_data, "Add item") ID = common.generate_random(table) table.append([ID, *inputs]) return table
def choose_by_dic(dic_function, table, *args): inputs = ui.get_inputs(["Choose option: "], " ") option = inputs[0] exit_code = 0 if option == "1": dic_function["1"](table) elif option == "2": dic_function["2"](table) elif option == "3": id_ = ui.get_inputs(["Which ID do you want to remove? "], "") dic_function["3"](table, id_) elif option == "4": id_ = ui.get_inputs(["Which ID do you want to update? "], "") dic_function["4"](table, id_) elif option == "5": dic_function["5"](table) elif option == "6": dic_function["6"](table, *args) elif option == "0": main.main() else: raise KeyError("There is no such option.") return exit_code
def add(table): """ Asks user for input and adds it into the table. Args: table: table to add new record to Returns: Table with a new record """ user_input = ui.get_inputs(['Title', 'manufacturer', 'price', 'in_stock'], "Please provide information") while common.is_number(user_input[2]) and common.is_number([3]) is True: ui.print_error_message('Error: Price and Stock value must be numbers') user_input = ui.get_inputs( ['Title', 'manufacturer', 'price', 'in_stock'], "Please provide information") continue new_id = common.generate_random(table) new_record = [new_id] + user_input table += [new_record] data_manager.write_table_to_file('store/games.csv', table) return table
def remove(table, id_): row_counter = 0 table = data_manager.get_table_from_file("accounting/items.csv") id_ = ui.get_inputs( [""], "Please provide the ID of the item you want to remove: ") for line in table: row_counter += 1 if id_[0] == line[0]: table.remove(line) data_manager.write_table_to_file("accounting/items.csv", table) os.system("clear") show_table(table) return table elif id_[0] != line[0] and row_counter == len(table): ui.print_error_message("There is no such ID!")
def add(table): """ Asks user for input and adds it into the table. Args: table (list): table to add new record to Returns: list: Table with a new record """ new_list_to_add = [] new_list_to_add.append(common.generate_random(table)) new_list_to_add.extend(ui.get_inputs(["Please add the Name: "], "")) new_list_to_add.extend(ui.get_inputs(["Please add the Price: "], "")) new_list_to_add.extend(ui.get_inputs(["Please add the month: "], "")) new_list_to_add.extend(ui.get_inputs(["Please add the day: "], "")) new_list_to_add.extend(ui.get_inputs(["Please add the year: "], "")) table.append(new_list_to_add) # hozzáadni a csv filehoz data_manager.write_table_to_file("sales/sales.csv", table) return table
def start_module(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ filename = 'hr/persons.csv' show_table(filename) options = ['Add record', 'Remove record', 'Update record', 'Get oldest person', 'Get persons closest to avarage'] while True: try: ui.print_menu("Human resources manager", options, "Back to menu") inputs = ui.get_inputs(["Please enter a number: "], "") option = inputs[0] filecontent = data_manager.get_table_from_file(filename) if option == "1": filecontent = add(filecontent) elif option == "2": remove_id = ui.get_inputs( ['ID: '], 'Enter ID to remove item from the list' )[0] remove(filecontent, remove_id) elif option == "3": update_id = ui.get_inputs( ['ID: '], 'Enter ID to update item in the list' )[0] update(filecontent, update_id) elif option == "4": ui.print_result(get_oldest_person( filecontent), "Oldest person or people: ") ui.get_inputs([''], 'Press Enter to continue') elif option == "5": ui.print_result(get_persons_closest_to_average( filecontent), "Closest to average: ") ui.get_inputs([''], 'Press Enter to continue') elif option == "0": break elif option == '': raise KeyError("Please enter a valid input") else: raise KeyError("There is no such option.") data_manager.write_table_to_file(filename, filecontent) show_table(filename) except KeyError as err: show_table(filename) ui.print_error_message(str(err))
def add(table): """ Asks user for input and adds it into the table. Args: table (list): table to add new record to Returns: list: Table with a new record """ list_labels = ["name: ", "birth_year: "] wanna_stay = True while wanna_stay: new_product = ui.get_inputs(list_labels, "Please provide person information") new_product.insert(0, common.generate_random(table)) table.append(new_product) next_step = ui.get_inputs( [""], "Press 0 to save & exit or 1 to add another person.")[0] if next_step == "0": data_manager.write_table_to_file("hr/persons.csv", table) wanna_stay = False return table
def start_module(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ table = data_manager.get_table_from_file("accounting/items.csv") list_options = ["Show table", "Add new record", "Remove record", "Update record", "Highest profit year", "Average profit in year"] while True: ui.print_menu("Accounting manager", list_options, "Back to main menu") inputs = ui.get_inputs(["Please enter a number: "], "") option = inputs[0] if option == "1": show_table(table) elif option == "2": add(table) elif option == "3": id_ = ui.get_inputs(["ID: "], "Please type ID to remove") table = remove(table, id_) elif option == "4": id_ = ui.get_inputs(["ID: "], "Please type ID to update") table = update(table, id_) elif option == "5": ui.print_result(which_year_max(table), "Highest profit year is") elif option == "6": year = ui.get_inputs(["Please enter year: "], "") ui.print_result(avg_amount(table, year[0]), "Averege amount is") elif option == "0": break else: ui.print_error_message("Choose something else!")
def add(table, list_titles, csv_file): """ Asks user for input and adds it into the table. Args: table (list): table to add new record to Returns: list: Table with a new record """ new_item = ui.get_inputs(list_titles, " ") table.append(new_item) new_item.insert(0, generate_random(table)) data_manager.write_table_to_file(csv_file, table) return table
def add(table): """ Asks user for input and adds it into the table. Args: table: table to add new record to Returns: Table with a new record """ title = "Provide data: " list_labels = ["Name:", "Birth Year:"] inputs = ui.get_inputs(list_labels, title) table = common.adding_new_line_to_table(inputs,table) return table
def add_universal(table, title_list): new_record = [] add_index_start_for_name_rows = 1 list_labels = title_list[add_index_start_for_name_rows:] id_record = generate_random(table) inputs_list = ui.get_inputs(list_labels, "") # Add input to list with nessery attributes # Add new ID - random new_record.append(id_record) # Iteration by rows for row in inputs_list: new_record.append(row) # Append new row to the table. table.append(new_record) return table
def add(table): """ Asks user for input and adds it into the table. Args: table: table to add new record to Returns: Table with a new record """ new_person_list = ui.get_inputs(['Name', 'Birth year'], 'Adding new person to data') new_person_list.insert(0, common.generate_random(table)) # adding ID new_person_list.insert(0, str(len(table))) # adding short ID new_person_list[NAME_INDEX] = new_person_list[NAME_INDEX].strip() if common.is_year(new_person_list[AGE_INDEX]): table.append(new_person_list) return table
def add(table): """ Asks user for input and adds it into the table. Args: table (list): table to add new record to Returns: list: Table with a new record """ inputs = ui.get_inputs(["Month: ", "Day: ", "Year: ", "Type: ", "Amount: "], "Add item") MONTH, DAY, YEAR, TYPE, AMOUNT = inputs ID = common.generate_random(table) table.append([ID, MONTH, DAY, YEAR, TYPE, AMOUNT]) return table
def check_user_inp(labels, i): user_inp = [] for item in labels: acceptable_inp = False while acceptable_inp is False: user_single_inp = ui.get_inputs([item], "Please provide information") if check_length(user_single_inp) is not False: if is_number(labels[i]) is not False: user_inp.append(*user_single_inp) acceptable_inp = True user_inp.append(*user_single_inp) acceptable_inp = True # if item == in range(2, 4): return user_inp
def choose(): inputs = ui.get_inputs(["Please enter a number: "], "") option = inputs[0] if option == "1": store.start_module() elif option == "2": hr.start_module() elif option == "3": tool_manager.start_module() elif option == "4": accounting.start_module() elif option == "5": selling.start_module() elif option == "6": crm.start_module() elif option == "0": sys.exit(0) else: raise KeyError("There is no such option.")
def choose(): inputs = ui.get_inputs(["Please enter a number: "], "") option = int(inputs[0]) if option == 1: store.start() elif option == 2: hr.start() elif option == 3: tool_manager.start() elif option == 4: accounting.start() elif option == 5: selling.start() elif option == 6: crm.start() elif option == 0: sys.exit(0) else: raise KeyError("There is no such option.")
def choose(): inputs = ui.get_inputs(["Please enter a number: "], "") option = inputs[0] if option == '1': store.start() elif option == '2': hr.start() elif option == '3': tool_manager.start() elif option == '4': accounting.start() elif option == '5': selling.start() elif option == '6': crm.start() elif option == '0': sys.exit(0) else: raise KeyError("There is no such option.")
def add(table, list_labels, file_name): id_ = [generate_random(table)] inputs = (id_ + ui.get_inputs(list_labels, "")) table.append(inputs) data_manager.write_table_to_file(file_name, table) return table
def comm_remove(table): id_ = ui.get_inputs(["id: "], "Give me an id: ") for i in range(len(table)): if table[i][0] == id_[0]: del table[i] break