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 key = common.check_for_key(id_, table) if key == None: ui.print_error_message('Key does not exist') else: return_inputs = ui.get_inputs(['Name', 'Mail', 'Subscribed'], 'Enter New Values') modif_index = key table[modif_index][NAME] = return_inputs[FIRST_PROP] table[modif_index][MAIL] = return_inputs[SECOND_PROP] table[modif_index][SUBSCRIBED] = return_inputs[THIRD_PROP] data_manager.write_table_to_file('crm/customers.csv', table) return table
def add(table): """ first_question = "Please add the Title: " second_question = "Please add the Manufacturer: " third_question = "Please add the Price: " fourth_question = "Please add the Stock: " """ new_list_to_add = [] new_list_to_add.append(common.generate_random(table)) new_list_to_add.extend(ui.get_inputs(["Please add the Title: "], "")) new_list_to_add.extend(ui.get_inputs(["Please add the Manufacturer: "], "")) new_list_to_add.extend(ui.get_inputs(["Please add the Price: "], "")) new_list_to_add.extend(ui.get_inputs(["Please add the Stock: "], "")) table.append(new_list_to_add) # hozzáadni a csv filehoz data_manager.write_table_to_file("store/games.csv", 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 """ # your code 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 index in range(len(table)): if table[index][0] == id_: addnew = ui.get_inputs( ['title of item: ', 'price of item: ', 'month of item: ', 'day of item: ', 'year of item: '], 'Updating item of Sales') addnew.insert(0, id_) table[index] = addnew 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 """ table = data_manager.get_table_from_file(FILE_NAME) options = [ ('Display table', lambda: display_table(table)), ('Add transaction', lambda: add(table)), ("Modify transaction data", lambda: update(table)), ("Remove transaction data", lambda: remove(table)), ("Display cheapest item", lambda: display_cheapest_item(table)), ("Display items sold between the dates", lambda: display_items(table)), ] stay = True while stay: ui.print_menu('Sales', options, 'Back to main menu') try: stay = common.choose(options, table) except KeyError as err: ui.print_error_message(err) data_manager.write_table_to_file(FILE_NAME, 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 """ # your code '''user_input = ui.get_inputs(['name', 'manufacturer', 'purchase_date', 'durability'],"Please provide your personal information") new_id = common.generate_random(table) new_record = [new_id] + user_input table += [new_record] data_manager.write_table_to_file('inventory/inventory.csv', table) return table''' user_input = ui.get_inputs(['name', 'manufacturer', 'purchase_date', 'durability'],"Please provide information") while common.is_number(user_input[2]) is False or common.is_number(user_input[3]) is False: ui.print_error_message('Error: Price and Stock value must be numbers') user_input = ui.get_inputs(['Title', 'manufacturer', 'purchase_date', 'durability'],"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('inventory/inventory.csv', table) 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 """ new_line = ["", "", "", "", "", ""] new_line[0] = common.generate_random(table) title = ui.get_inputs(["What's the title of the game? "], "") price = ui.get_inputs(["What's the actual sale price of the game? "], "") month = ui.get_inputs(["When was it sold? Month of transaction: "], "") day = ui.get_inputs(["When was it sold? Day of transaction: "], "") year = ui.get_inputs(["When was it sold? Year of transaction: "], "") new_line[1] = title[0] new_line[2] = price[0] new_line[3] = month[0] new_line[4] = day[0] new_line[5] = year[0] table.append(new_line) data_manager.write_table_to_file('sales/sales.csv', table)
def choose(): inputs = ui.get_inputs(['Enter a number: '], '') option = inputs[0] if option == "1": show_table(TABLE) elif option == "2": add(TABLE) elif option == "3": id_get = ui.get_inputs([LIST_OF_TITLES[0]], "Enter the ID of the item you want to delete: ") id_ = ''.join(id_get) remove(TABLE, id_) data_manager.write_table_to_file(file_name, TABLE) elif option == "4": id_get = ui.get_inputs([LIST_OF_TITLES[0]], "Enter the ID of the item you want to modify: ") id_ = ''.join(id_get) table = update(TABLE, id_) data_manager.write_table_to_file(file_name, table) elif option == "5": ui.print_result(get_oldest_person(TABLE), "The oldest person is:") elif option == "6": ui.print_result(get_persons_closest_to_average(TABLE), "Closest to average: ") elif option == '0': raise ValueError while option not in OPTION: raise KeyError
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_line = ["", "", "", "", ""] new_line[0] = common.generate_random(table) title = ui.get_inputs(["What is the title?: "], "") manufacturer = ui.get_inputs(["What is the manufacturer adress?: "], "") price = ui.get_inputs(["What is the price?: "], "") in_stock = ui.get_inputs(["How much is in stock?: "], "") new_line[1] = title[0] new_line[2] = manufacturer[0] new_line[3] = price[0] new_line[4] = in_stock[0] table.append(new_line) data_manager.write_table_to_file('store/games.csv', table) return table
def choose(): while True: ui.print_menu("CRM", 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(['Please enter ID'], "") remove(table, id_) elif option == "4": id_ = ui.get_inputs(['Please enter ID'], "") update(table, id_) elif option == "5": result_get_longest_name_id = get_longest_name_id(table) ui.print_result(result_get_longest_name_id, "longest name ID ") elif option == "6": result_get_subscribed_emails = get_subscribed_emails(table) ui.print_result(result_get_subscribed_emails, "Subscribed customer(s):") elif option == "0": answer_list = ui.get_inputs( ["Do you want to save the changes? (Y/N)"], "") answer = answer_list[0].upper() if answer == "Y": data_manager.write_table_to_file('crm/customers.csv', table) elif answer == "N": break else: ui.print_error_message("Invalid answer.") else: ui.print_error_message("There is no such option.")
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 """ # you code table = data_manager.get_table_from_file('accounting/items_test.csv') options = [ 'Show table', 'Add', 'Remove', 'Update', 'Which year max', 'Avg amount' ] menu = None while menu == None: ui.print_menu('Accounting menu', options, 'Back to main') try: menu = choose(table) except KeyError as err: ui.print_error_message(err) data_manager.write_table_to_file('accounting/items_my_test.csv', table) pass
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 labels = ["Title: ", "Price: ", "Month: ", "Day: ", "Year: "] updated_row=[] temp_list=[] counter=0 ifWrong=True for row in table: if row[0] == id_[0]: ifWrong=False updated_row.append(id_[0]) temp_list=ui.get_inputs(labels, "Please put new data:") for rec in temp_list: updated_row.append(rec) table[counter]=updated_row counter+=1 if ifWrong == True: ui.print_error_message("Id doesn't exist") data_manager.write_table_to_file(file_name, table) return table
def choose(): inputs = ui.get_inputs(['Enter a number: '], '') option = inputs[0] if option == "1": show_table(TABLE) elif option == "2": add(TABLE) elif option == "3": id_get = ui.get_inputs([LIST_OF_TITLES[0]],"Enter the ID of the item you want to delete: ") id_=''.join(id_get) remove(TABLE,id_) data_manager.write_table_to_file(file_name, TABLE) elif option == "4": id_get = ui.get_inputs([LIST_OF_TITLES[0]],"Enter the ID of the item you want to modify: ") id_=''.join(id_get) table = update(TABLE,id_) data_manager.write_table_to_file(file_name, table) elif option == "5": ui.print_result (get_longest_name_id(TABLE), "The longest name is:") elif option == "6": ui.print_result(get_subscribed_emails(TABLE), "The names and emails of the subscribed customers:") elif option == '0': raise ValueError while option not in OPTION: raise KeyError
def update(table, id_): row_counter = 0 id_ = ui.get_inputs( [""], "Please provide the ID of the item you want to update: ") for line in table: row_counter += 1 if id_[0] in line[0]: newmonth = ui.get_inputs( [""], "Please add a new record for month: ") line[1] = "".join(newmonth) newday = ui.get_inputs([""], "Please add a new record for day: ") line[2] = "".join(newday) newyear = ui.get_inputs([""], "Please add a new record for year: ") line[3] = "".join(newyear) newtype = ui.get_inputs([""], "Please add a new record for type: ") line[4] = "".join(newtype) newamount = ui.get_inputs( [""], "Please add a new record for amount: ") line[5] = "".join(newamount) 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: table (list): table with a new record """ name = '' while not name: name = ui.get_inputs(['Customer name:'], "Please provide new customer data")[0] if not name: ui.print_error_message("It's not a proper name.") is_correct = False while not is_correct: e_mail = ui.get_inputs(['Customer e-mail:'], " ")[0] is_correct = check_email(e_mail) if not is_correct: ui.print_error_message("This isn't proper e-mail") is_subscribed = '' while is_subscribed not in ['0', '1']: is_subscribed = ui.get_inputs(['Is the customer subscribed to the newsletter [1 - yes / 0 - no]:'], "")[0] if is_subscribed not in ['0', '1']: ui.print_error_message("Acceptable answer are only 0 for 'no' and 1 for 'yes'.") new_record = [common.generate_random(table), name, e_mail, is_subscribed] table.append(new_record) 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 """ # your code data = data_manager.get_table_from_file('sales/sales.csv') sales_options = [ "Show Table", "Add", "Remove", "Update", "Lowest Price Item ID", "Items Sorted Between Date" ] while True: ui.print_menu('Sales Main Menu', sales_options, 'Back To Menu') try: data = choose_sale(data) except KeyError as err: ui.print_error_message(err) if not data[0]: data_manager.write_table_to_file('sales/sales.csv', data[1]) return True ui.clear_terminal()
def update(table, id_): """ Updates specified record in the table. Ask users for new data. Args: table: list in which record should be updated id_ (str): id of a record to update Returns: list: table with updated record """ for line in table: if line[0] == id_: item_to_be_changed = ui.get_inputs([ "What do you want to update (\"title\"/\"manufacturer\"/\"price\"): " ], "") if item_to_be_changed[0] == "title": title = ui.get_inputs(["What is the new title: "], "") line[1] = title[0] elif item_to_be_changed[0] == "manufacturer": manufacturer = ui.get_inputs( ["What is the new manufacturer: "], "") line[2] = manufacturer[0] elif item_to_be_changed[0] == "price": price = ui.get_inputs(["What is the new price: "], "") line[3] = price[0] elif item_to_be_changed[0] == "in_stock": in_stock = ui.get_inputs(["How much is in stock: "], "") line[3] = in_stock[0] data_manager.write_table_to_file("store/games.csv", table) return table
def display_question(id, count_view=True): # view counter += 1 question_file_name = current_file_path + "/data/question.csv" question_list = data_manager.get_table_from_file(question_file_name, (4, 5, 6)) for row in question_list: if row[0] == id: title = row[4] message = row[5] if count_view: row[2] = str(int(row[2]) + 1) question_list = data_manager.get_timeform_to_stamp(question_list) data_manager.write_table_to_file(question_file_name, question_list, (4, 5, 6)) break answer_file_name = current_file_path + "/data/answer.csv" answer_list = data_manager.get_table_from_file(answer_file_name, (4, 5)) list_answers = [] for row in answer_list: if row[3] == id: list_answers.append(row) return render_template('display_question.html', id=id, title=title, message=message, list_answers=list_answers)
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 """ # your code '''user_input = ui.get_inputs(['name', 'manufacturer', 'purchase_date', 'durability'],"Please provide your personal information") new_id = common.generate_random(table) new_record = [new_id] + user_input table += [new_record] data_manager.write_table_to_file('inventory/inventory.csv', table) return table''' labels = ['name', 'manufacturer', 'purchase_date', 'durability'] purchase_date = 2 durability = 3 user_inp = common.check_user_inp_2num(labels, purchase_date, durability) new_id = common.generate_random(table) new_record = [new_id] + user_inp table += [new_record] data_manager.write_table_to_file('inventory/inventory.csv', table) return table
def add_image(id): if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also # submit a empty part without filename if file.filename == '': flash('No selected file') return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) # filename-to-table question_file_name = current_file_path + "/data/question.csv" question_list = data_manager.get_table_from_file( question_file_name, (4, 5, 6)) for row in question_list: if row[0] == id: row[6] = '/images/' + filename break # update csv question_list_csv_format = data_manager.get_timeform_to_stamp( question_list) # question_list_csv_format = data_manager.add_item_to_table(question_list_csv_format, request.form) data_manager.write_table_to_file(question_file_name, question_list_csv_format, (4, 5, 6)) return redirect('/') return render_template('file_upload.html')
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 """ option = "" reading_file_successful = True try: table = data_manager.get_table_from_file('accounting/items.csv') except FileNotFoundError: ui.print_error_message('File not found, couldn\'t run the module.') reading_file_successful = False while option != "0" and reading_file_successful: handle_menu() try: table, option = choose(table) except KeyError as err: ui.print_error_message(err) if reading_file_successful: data_manager.write_table_to_file("accounting/items.csv", 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 """ return_inputs = ui.get_inputs( ['Title', 'Price', 'Year', 'Month', 'Day', 'Key From Customers'], "Please enter a new record.") key = str(common.generate_random(table)) table.append([ key, return_inputs[FIRST_PROP], str(return_inputs[SECOND_PROP]), str(return_inputs[FOURTH_PROP]), str(return_inputs[FIFTH_PROP]), str(return_inputs[THIRD_PROP]), return_inputs[SIXTH_PROP] ]) data_manager.write_table_to_file('sales/sales.csv', table) 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 """ readed_file = data_manager.get_table_from_file(table) POSITION_OF_ID = 0 i = 0 while i < len(readed_file): if id_ == readed_file[i][POSITION_OF_ID]: elements_to_update = ["Title", "Price", "Month", "Day", "Year"] inputs = ui.get_inputs(elements_to_update, "Please answer: ") list_of_checks = [ checking_M_D_Y(inputs, 2, 0, 13, "Month"), checking_M_D_Y(inputs, 3, 0, 32, "Day"), checking_M_D_Y(inputs, 4, 0, 2020, "Year"), checking_price(inputs, "Price") ] if "ERROR" in list_of_checks: return table inputs.insert(0, id_) readed_file.remove(readed_file[i]) readed_file.insert(i, inputs) i += 1 data_manager.write_table_to_file(table, readed_file) 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 """ key = common.check_for_key(id_, table) if key == None: ui.print_error_message('Key does not exist') else: return_inputs = ui.get_inputs( ['Title', 'Price', 'Year', 'Month', 'Day', 'Key From Customers'], "Please enter a new record.") modif_index = key table[modif_index][TITLE] = return_inputs[FIRST_PROP] table[modif_index][PRICE] = return_inputs[SECOND_PROP] table[modif_index][MONTH] = return_inputs[FOURTH_PROP] table[modif_index][DAY] = return_inputs[FIFTH_PROP] table[modif_index][YEAR] = return_inputs[THIRD_PROP] table[modif_index][CUSTOMER_ID] = return_inputs[SIXTH_PROP] data_manager.write_table_to_file('sales/sales.csv', 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 """ user_input = ui.get_inputs(['month', 'day', 'year', 'type', ' amount'], "Please provide information") while common.is_number(user_input[2]) is False or common.is_number( user_input[3]) 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 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 """ element_index_in_list = 0 for row in table: if id_[element_index_in_list] in row: inputs = ui.get_inputs(['Full name', 'Year of birth'], 'Enter the details...') row[1] = inputs[0] row[2] = inputs[1] else: common.ID_error() data_manager.write_table_to_file(file_name, table) 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 """ new_line = ["", "", "", "", ""] new_line[0] = common.generate_random(table) name = ui.get_inputs(["What's the name of the game? "], "") manufacturer = ui.get_inputs(["Who is the manufacturer? "], "") year = ui.get_inputs(["When was it bought? Year of transaction: "], "") durability = ui.get_inputs(["How many years is it still durable? "], "") new_line[1] = name[0] new_line[2] = manufacturer[0] new_line[3] = year[0] new_line[4] = durability[0] table.append(new_line) data_manager.write_table_to_file('inventory/inventory.csv', table) 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 """ id_index = 0 wrong_id = True while wrong_id: for line in table: if line[0] == id_[0]: table[id_index] = ui.get_inputs( ["Month: ", "Day: ", "Year: ", "Type: ", "Amount: "], "Please provide the necessary information") table[id_index].insert(0, id_[0]) wrong_id = False else: id_index += 1 data_manager.write_table_to_file("accounting/items_test.csv", table) return table
def update(table, id_): for i in table: if i[0] == id_: i[1] = ui.get_inputs(["What should i update the title to: "], "") i[2] = ui.get_inputs( ["What should i update the manufacturer to? "], "") i[3] = ui.get_inputs(["What should i update the price to? "], "") i[4] = ui.get_inputs(["What sould i update the stock number? "], "") data_manager.write_table_to_file("store/games.csv", table) """ Updates specified record in the table. Ask users for new data. Args: table: list in which record should be updated id_ (str): id of a record to update Returns: list: table with updated record """ # your code return table
def remove(table, id_): """ Remove a record with a given id from the table. Args: table (list): table to remove a record from id_ (str): id of a record to be removed Returns: list: Table without specified record. """ wanna_stay = True current_iterates = 0 max_iterates = len(table) while wanna_stay: for i, v in enumerate(table): if v[0] == id_: table.remove(table[i]) elif v[0] != id_ and current_iterates < max_iterates: current_iterates += 1 else: ui.print_error_message("There is nothing with the given ID!") next_step = ui.get_inputs( [""], "Press 0 to exit or 1 to remove another person.")[0] if next_step == '0': data_manager.write_table_to_file("hr/persons.csv", table) wanna_stay = False else: id_ = ui.get_inputs(["Please type ID to remove: "], "\n")[0] continue return table
def add(table): """ Asks user for input and adds it into the table. :param table: list of all items in database :return: updated table """ new_record = [] new_record.append(common.generate_random(table)) new_record.append(input("Enter " + update_options[0] + ": ")) i = 1 while i < len(update_options): handle_inputs = input("Enter " + update_options[i] + ": ") if common.check_if_input_is_number(handle_inputs): if common.check_if_data_is_in_range(i, handle_inputs, border_conditions): new_record.append(handle_inputs) i += 1 else: ui.print_error_message("error!") updated_table = table + [new_record] data_manager.write_table_to_file(file_name, table=updated_table) show_table(updated_table) return updated_table
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