Пример #1
0
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_price = 3
    new_count = 4
    while True:
        new_record = ui.get_inputs(input_list,
                                   "Please provide personal information:\n")
        new_record.insert(0, common.generate_random([]))
        if not new_record[new_price].replace('.', '').isdigit():
            ui.print_error_message("Provide correct price")
        elif not new_record[new_count].isdigit():
            ui.print_error_message("Provide correct count")
        else:
            break
    table = table + [new_record]
    return table
Пример #2
0
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
    """

    new_price = 3
    new_count = 4
    index = common.get_ind(table, game_id, id_)
    for element in table:
        if element[game_id] == id_:
            while True:
                new_record = ui.get_inputs(
                    input_list, "Please provide personal information:\n")
                new_record.insert(0, common.generate_random([]))
                if not new_record[new_price].replace('.', '').isdigit():
                    ui.print_error_message("Provide correct price")
                elif not new_record[new_count].isdigit():
                    ui.print_error_message("Provide correct count")
                else:
                    table[index] = new_record
                    break
    return table
Пример #3
0
def add(table):
    list_labels = ["Title", "Price", "Month", "Day", "Year"]
    new_id = common.generate_random()
    new_data = ui.get_inputs(list_labels, "")
    new_data.insert(0, new_id)
    table = common.add_line_to_file("sales/sales.csv", new_data)
    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
    """

    # your code
    userinput_title = ui.get_inputs("Title: ", "")
    userinput_price = ui.get_inputs("Price: ", "")
    userinput_month = ui.get_inputs("Month: ", "")
    userinput_day = ui.get_inputs("Day: ", "")
    userinput_year = ui.get_inputs("Year: ", "")

    ID = 0
    TITLE = 1
    PRICE = 2
    MONTH = 3
    DAY = 4
    YEAR = 5

    for sublist in table:
        if id_ in sublist:
            sublist[ID] = common.generate_random(table)
            sublist[TITLE] = userinput_title
            sublist[PRICE] = userinput_price
            sublist[MONTH] = userinput_month
            sublist[DAY] = userinput_day
            sublist[YEAR] = userinput_year
    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
    """

    list_labels = [
        "name: ", "manufacturer: ", "purchase_year: ", "durability: "
    ]
    wanna_stay = True
    while wanna_stay:
        new_product = ui.get_inputs(list_labels,
                                    "Please provide new 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 information.")[0]
        if next_step == "0":
            data_manager.write_table_to_file("inventory/inventory.csv", table)
            wanna_stay = False
    return table
Пример #6
0
def add(table):
    """
    Ask user for inputs and update the table.
    :param table: database - a text file with data records from accounting module
    :return: updated table with new record
    """
    show_table(table)
    new_record = []
    new_record.append(common.generate_random(table))

    i = 0
    while i < len(options):
        user_input = ui.get_inputs(["Enter {}".format(options[i])], "")
        if common.data_types_dependent_on_numbers(options[i]):
            if common.check_is_number(
                    user_input) and common.check_data_in_range(
                        user_input, options[i]):
                new_record.append(user_input)
                i += 1
            else:
                ui.print_error_message(
                    "Please provide a correct value!".upper())
        else:
            new_record.append(user_input)
            i += 1

    updated_table = table + [new_record]
    data_manager.write_table_to_file(file_name, updated_table)
    show_table(updated_table)

    return updated_table
Пример #7
0
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
    """

    message = ("Please check your input")
    while True:
        id_ = common.generate_random(table)
        datauser = ui.get_inputs([
            'Input client name: ', 'Input client email: ',
            'Is she/he subscribed to the newsletter? 1/0 = yes/no  '
        ], "Please provide your personal information")
        if isinstance(datauser[0],
                      str) and datauser[2] == '0' or datauser[2] == '1':
            table.append([id_, datauser[0], datauser[1], datauser[2]])
            label = "You have just added new client: "
            ui.print_result(datauser, label)
            data_manager.write_table_to_file("crm/customers.csv", table)
            break
        else:
            ui.print_error_message(message)

    return table
Пример #8
0
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
    """

    ID = common.generate_random(table)
    elements_to_add = ["Name", "Email", "Subscribed"]
    inputs = ui.get_inputs(elements_to_add, "Please answer: ")

    list_of_checks = [
        checking_Name(inputs),
        checking_Email(inputs),
        checking_Subscribed(inputs)
    ]

    if "ERROR" in list_of_checks:
        return table

    our_file_to_edit = open(f"{table}", "a")
    inputs.insert(0, f"{ID}")
    our_file_to_edit.write(";".join(inputs) + "\n")
    our_file_to_edit.close()
    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
    """

    message = ("Please check your input")
    CURRENT_YEAR = 2020
    id_ = common.generate_random(table)
    datauser = ui.get_inputs(['input your name: ', 'Choose your hire year:  '],
                             "Please provide your personal information")
    datauser[1] = int(datauser[1])
    # while isinstance(datauser[0], str) and isinstance(datauser[1], int) and datauser[1] <= CURRENT_YEAR:
    if isinstance(datauser[0], str) and isinstance(
            datauser[1], int) and datauser[1] <= CURRENT_YEAR:
        table.append([id_, datauser[0], str(datauser[1])])
        label = "You added the new emploee"
        ui.print_result(datauser, label)
        data_manager.write_table_to_file("hr/persons.csv", table)
    else:
        ui.print_error_message(message)
    return table
Пример #10
0
def add(table):
    """
    Asks user for input and adds it into the table.
    :param table: text file where are included some information.
    :return: list with a new record
    """
    new_record = []
    new_record.append(common.generate_random(table))
    new_record.append(input("Enter " + update_options[0] + ": "))
    new_record.append(input("Enter " + update_options[1] + ": "))
    new_record.append(input("Enter " + update_options[2] + ": "))
    i = 3
    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("Something went wrong!")

    updated_table = table + [new_record]
    data_manager.write_table_to_file(file_name, table=updated_table)
    show_table(updated_table)

    return updated_table
Пример #11
0
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(
        ["name ", "developer ", "price ", "numbers is stock "],
        "Input: ID, name, developer, price, numbers is stock")
    genereted_id = common.generate_random(table)

    table_temp = table.append([
        genereted_id,
        inputs[0],
        inputs[1],
        inputs[2],
        inputs[3],
    ])  # inputs[0] = można zamienić na wygenerowane ID

    data_manager.write_table_to_file("store/games.csv", table)

    return table
Пример #12
0
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)
    month = ui.get_inputs(["When was it bought? Month of transaction: "], "")
    day = ui.get_inputs(["When was it bought? Day of transaction: "], "")
    year = ui.get_inputs(["When was it bought? Year of transaction: "], "")
    in_out = ui.get_inputs(["Was it input or outflaw? (\"in\"/\"out\") "], "")
    amount = ui.get_inputs(["Amount of transaction: "], "")
    new_line[1] = month[0]
    new_line[2] = day[0]
    new_line[3] = year[0]
    new_line[4] = in_out[0]
    new_line[5] = amount[0]
    table.append(new_line)
    data_manager.write_table_to_file('accounting/items.csv', table)

    return table
Пример #13
0
def add(table):
    list_titles = ['title', 'price', 'month', 'day', 'year']
    new_item = [common.generate_random(table)] + ui.get_inputs(
        list_titles, table)
    table.append(new_item)

    return table
Пример #14
0
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
Пример #15
0
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
    """

    count = 0
    searched_index = -1
    in_it = False
    for i in table:
        if i[0] == id_:
            searched_index = count
            in_it = True
        count += 1

    if in_it:
        to_change = ui.get_inputs(list_labels, "")
        to_change.insert(0, common.generate_random(table))
        table[searched_index] = to_change

        return table

    else:
        ui.print_error_message("ID is not found")
Пример #16
0
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
Пример #17
0
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 e-mail: "],""))
    new_list_to_add.extend(ui.get_inputs(["Is She/He a Subscriber to the Newsletter? 1/0 = yes/no \n"],""))
    '''common.convert(ui.get_inputs)
    if ui.get_inputs == 1:
        ui.get_inputs = str
        new_list_to_add.append
    if ui.get_inputs == 0:
        ui.get_inputs = str
        new_list_to_add.append'''
    
    
    table.append(new_list_to_add) # hozzáadni a csv filehoz
    data_manager.write_table_to_file("crm/customers.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)
    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
Пример #19
0
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
Пример #20
0
def add(table):
    """
    Asks user for input and adds it into the table.

    Args:EAD
        table (list): table to add new record to

    Returns:
        list: Table with a new record
    """


    random_id = common.generate_random(table)
    title_list = ["month","day","year","type","amount"]
    inputs = ui.get_inputs(title_list, "Enter new line")
    inputs.insert(0, random_id)
    table.append(inputs)

    return table



    """#table[-1] = ['12345123', '12', '2', '31', 'in' ,'34']
    add_mar_hozza = ['12345123', '12', '2', '31', 'in' ,'34']
    #12345678 12 2 2019 in 12
    table.append(add_mar_hozza)
    print(table)"""

    """table = data_manager.get_table_from_file("items.csv")
Пример #21
0
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")
Пример #22
0
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)
Пример #23
0
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
    """

    ID = common.generate_random(table)
    elements_to_add = ["Title", "Price", "Month", "Day", "Year"]
    inputs = ui.get_inputs(elements_to_add, "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

    our_file_to_edit = open(f"{table}", "a")
    inputs.insert(0, f"{ID}")
    our_file_to_edit.write(";".join(inputs) + "\n")
    our_file_to_edit.close()
    return table
Пример #24
0
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_year = 3
    new_durability = 4
    while True:
        new_record = ui.get_inputs(input_list,
                                   "Please provide personal information:\n")
        new_record.insert(0, common.generate_random([]))
        if not new_record[new_year].isdigit() or not int(
                new_record[new_year]) >= 1900 or not int(
                    new_record[new_year]) <= 2021:
            ui.print_error_message(
                "Wrong value typed. Year must be higher than 1900 and lower than 2021"
            )
        if not new_record[new_durability].isdigit() or not int(
                new_record[new_durability]) >= 1 or not int(
                    new_record[new_durability]) <= 20:
            ui.print_error_message(
                "Wrong value typed. Durability must be higher than 0 and lower than 20"
            )
        else:
            break
    table = table + [new_record]

    return table
Пример #25
0
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
Пример #26
0
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
Пример #27
0
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
Пример #28
0
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
    labels = ['Month', 'Day', 'Year', 'Operation', 'Amount (USD)']
    new_record_list = ui.get_inputs(labels, 'Adding new record to data')
    new_record_list.insert(0, common.generate_random(table))  # adding ID
    new_record_list.insert(0, str(len(table)))  # adding short ID
    if not common.is_month(new_record_list[MONTH_INDEX]):
        return table
    if not common.is_day(new_record_list[DAY_INDEX], new_record_list[MONTH_INDEX]):
        return table
    if not common.is_positive_int(new_record_list[YEAR_INDEX]):
        return table
    if not is_operation(new_record_list[OPERATION_INDEX]):
        return table
    if not common.is_positive_int(new_record_list[AMOUNT_INDEX]):
        return table
    return table.append(new_record_list)
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 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
    headers = header_info()
    numbers_of_values = len(headers)
    temp_list = []
    for index, header_title in enumerate(headers):
        if index == 0:
            temp_list.append(common.generate_random(table))

        else:
            values = value_checker(header_title)
            temp_list.extend(values)
            # temp_list.append()

    table.append(temp_list)
    return table
def add(table):
    list_titles = ['title',
                   'price',
                   'month',
                   'day',
                   'year']
    new_item = [common.generate_random(
        table)] + ui.get_inputs(list_titles, table)
    table.append(new_item)

    return table
def main():
    general_config = ConfigParser.ConfigParser()
    config = ConfigParser.ConfigParser()

    general_config.read('config.cfg')
    config.read('config_user2.cfg')
    host = general_config.get('networking', 'ip')
    port = int(general_config.get('networking', 'port'))
    lower_range_DH = int(general_config.get('crypto', 'lower_range_DH'))
    upper_range_DH = int(general_config.get('crypto', 'upper_range_DH'))

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host,port))

    other_N, other_e = config.get('crypto_user1', 'N'), config.get('crypto_user1', 'e')
    other_N, other_e = int(other_N), int(other_e)

    N = config.get('crypto_user2', 'N')
    e = config.get('crypto_user2', 'e')
    d = config.get('crypto_user2', 'd')
    p = config.get('crypto_user2', 'p')
    q = config.get('crypto_user2', 'q')

    signer = RSASign(s, d, N)
    verifier = RSAVerify(s, other_e, other_N)

    DH_prime = common.generate_random()
    generator = common.find_generator(DH_prime)
    signer.sign_and_send(DH_prime)

    x2 = random.randint(lower_range_DH, upper_range_DH)
    y2 = common.modfun(generator, x2, DH_prime)
    signer.sign_and_send(y2)

    y1 = verifier.recv_and_verify()
    y12 = common.modfun(y1, x2, DH_prime)

    print "[+] Negotiated session key", y12