Beispiel #1
0
def get_correct_data_types(user_input, answer_type, alpha_string):
    """
    get_correct_data_types function change the type of input to
    it's expected type.

    Args:
        param1: user_input (str)
        param2: answer_type (the type which input should have)
        param3: alpha_string (bool)

    Returns:
        user_input (int or str)
    """
    if answer_type == int:
        try:
            user_input = int(user_input)
        except ValueError:
            user_input = None
            ui.print_error_message("Wrong value provided.\n")

    elif answer_type == str:
        if alpha_string:
            user_input_copy = user_input.replace(' ', '')

            if not user_input_copy.isalpha():
                user_input = None
                ui.print_error_message('It not alpha string.')

    return user_input
def main():
    while True:
        handle_menu()
        try:
            choose()
        except KeyError as err:
            ui.print_error_message(err)
def main():
    while True:
        handle_menu()
        try:
            choose()
        except KeyError as err:
            ui.print_error_message(err)
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 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)
Beispiel #6
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
Beispiel #7
0
 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.")
Beispiel #8
0
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
Beispiel #9
0
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
Beispiel #10
0
def main():
    while True:
        handle_menu()
        try:
            choose()
        except KeyError:
            ui.print_error_message('Wrong input! Please try again!')
def start_module():
    while True:
        options = ["Show table",
                   "Add",
                   "Remove",
                   "Update",
                   "How many different kinds of game are available of each manufacturer?",
                   "What is the average amount of games in stock of a given manufacturer?"]
        ui.print_menu("Stores", options, "Back to main menu")

        table = data_manager.get_table_from_file("store/games.csv")

        inputs = ui.get_inputs(["Please enter a number: "], "")
        option = inputs[0]
        try:
            if option == "1":
                show_table(table)
            elif option == "2":
                add(table)
            elif option == "3":
                id_ = ui.get_inputs(["Please provide ID to remove: "], "")
                remove(table, id_[0])
            elif option == "4":
                id_ = ui.get_inputs(["Please give me an ID to update: "], "")
                update(table, id_[0],)
            elif option == "5":
                get_counts_by_manufacturers(table)
            elif option == "6":
                manufacturer = ui.get_inputs(["Please Give me the Manufacturer Name: "], "")
                get_average_by_manufacturer(table, manufacturer)
            elif option == "0":
                break
        except KeyError as err:
            ui.print_error_message(str(err))
Beispiel #12
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")
Beispiel #13
0
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.
    """
    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:
        table.pop(searched_index)
    else:
        ui.print_error_message("ID not found")

    return table
Beispiel #14
0
def get_average_by_manufacturer(table, manufacturer):
    """
    Question: What is the average amount of games in stock of a given manufacturer?

    Args:
        table (list): data table to work on
        manufacturer (str): Name of manufacturer

    Returns:
         number
    """
    count = []
    try:
        for elements in table:
            if elements[2] == manufacturer:
                count.append(elements[4])

        x = 0
        for number in count:
            x += int(number)

        lastresult = x / len(count)

        return lastresult
    except ZeroDivisionError:
        ui.print_error_message("There is no such a Manufacturer")
Beispiel #15
0
def username_pass(lst, mail):
    tries = 3
    while True:
        User = ui.get_inputs(["Username: "******"Password: "******"Please provide the console informations")
        os.system('clear')
        password = User[1]
        new_pass = caesar(password, 5)
        User[1] = new_pass
        User = [[User[0]], [User[1]]]
        if User == lst:
            return True
        else:
            tries -= 1
            if tries == 0:
                verification_code = generate_random()
                ui.print_error_message("You have no more tries, sorry :(")
                server = smtplib.SMTP('smtp.gmail.com', 587)
                server.starttls()
                server.login("*****@*****.**", "Hermelin123?")
                msg = "Subject: ERP login \n" + "Dear " + str(lst[0][0]) + "," + "\nSomebody tried to enter your ERP account 3 times with wrong password.\nIf you want to change your password, use this verification code:\n" + \
                    str(verification_code)
                server.sendmail("*****@*****.**", mail, msg)
                server.quit()
                return verification_code
            ui.print_error_message("\nYou entered wrong password, you have " + str(tries) + " tries left\n")
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!")
Beispiel #17
0
def choose(table):
    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_to_remove = ui.get_inputs(['Enter id to remove: '], '')
        if common.is_this_record_exist(table, id_to_remove):
            remove(table, id_to_remove)
    elif option == "4":
        id_to_update = ui.get_inputs(['Enter id to update'], '')
        if common.is_this_record_exist(table, id_to_update):
            table = update(table, id_to_update)
    elif option == "5":
        year = which_year_max(table)
        ui.print_result(str(year), 'Best profit year')
    elif option == "6":
        year = ui.get_inputs(['which year?'], '')
        if year[0].isdigit():
            answear = avg_amount(table, year[0])
            ui.print_result(str(answear), 'Averge profit')
        else:
            ui.print_error_message('Wrong year')
    elif option == "0":
        return False
    else:
        raise KeyError("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
    """

    # 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
Beispiel #19
0
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 avg_amount(table, year):
    '''
    Function checks records from the date provided by user
    Every in and out value is summed, and divided by /
    amount of logs from provided year, giving an average profit

    Args:
        table: list with records
        year: ueser's input turned to integer

    Returns:
        avg_profit = int
    '''
    profit = 0
    data_of_given_year = []

    for item in table:
        if int(item[3]) == year:
            data_of_given_year.append(item)

    for record in data_of_given_year:
        if record[4] == 'in':
            profit += int(record[5])
        elif record[4] == 'out':
            profit -= int(record[5])
    try:
        avg_profit = profit / len(data_of_given_year)
        return avg_profit
    except ZeroDivisionError:
        ui.print_error_message('There are no record from provided year')
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()
Beispiel #22
0
def checking_M_D_Y(list_to_check, question_number, date_since, date_to,
                   which_question):
    if not list_to_check[question_number].isdigit() or not date_since < int(
            list_to_check[question_number]) < date_to:
        ui.print_error_message(
            f"Please write correct answer for question {which_question}")
        return "ERROR"
def check_year(table):
    """
    Function check if input year is in file, and return it as int if it is

    :param table: table to check if year is in it
    :return: input year as int
    """

    table_rev = [list(x) for x in zip(*table)
                 ]  # transposition of table to get list with all years
    year_column = table_rev[3]  # list with all years

    label = ""  # string will cointain years from file with no duplicates to be show during input
    for year in year_column:
        if str(year) not in label:
            label += str(year) + "  "

    while True:
        type_year = ui.get_inputs([label], 'Type year, or 0 to exit')
        if type_year[0] in year_column:
            return int(type_year[0])
        elif str(type_year[0]).isdigit() and int(type_year[0]) == 0:
            break
        else:
            ui.print_error_message('No such year in file')
Beispiel #24
0
def start_module():
    global repeat
    """
    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
    """
    #read from file to 2D table
    sales_list = common.read_from_file_to_table(filepath)
    repeat = True

    while repeat:
        #display Sales menu
        options = [
            "Display list", "Add entry", "Remove entry", "Update entry",
            "Get lowest price item", "Get items sold between time range"
        ]

        ui.print_menu("Sales menu", options, "Return to main menu")
        try:
            choose(sales_list)
        except KeyError as err:
            ui.print_error_message(str(err))
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
Beispiel #26
0
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)
Beispiel #27
0
def is_operation(operation):
    try:
        if operation == 'in' or operation == 'out':
            return True
    except:
        ui.print_error_message(operation + ' is not an operation')
    return False
Beispiel #28
0
def choose_option(table):

    inputs = ui.get_inputs(["Please enter a number: "], "")
    option = inputs[0]

    if option == "1":
        show_table(table)
    elif option == "2":
        table = add(table)
    elif option == "3":
        id_ = ui.get_inputs(["Id"],
                            "Please provide record you want to remove")[0]
        table = remove(table, id_)
    elif option == "4":
        id_ = ui.get_inputs(["Id"],
                            "Please provide record you want to update")[0]
        table = update(table, id_)
    elif option == "5":
        result = which_year_max(table)
        result = str(result)
        ui.print_result(result, "The year with the hightest profit is: ")
    elif option == "6":
        year = ui.get_inputs(
            ["Year"],
            "Please provide year for which you want to see profit")[0]

        try:
            result = avg_amount(table, year)
            result = str(result)
            ui.print_result(
                result, "The Avarage profit per item in {} is: ".format(year))
        except UnboundLocalError as err:
            ui.print_error_message("")

    return option, table
def common_remove(table, id_):
    for i in table:
        if i[0] == id_:
            table.remove(i)
            return table
    ui.print_error_message("This ID doesn't exist.")
    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

    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
Beispiel #31
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
Beispiel #32
0
def update_universal(table, id_, title_list):
    # temp index name
    element_index_id = 0
    element_index_start_without_id = 1

    # CUTING FRAGMENT OF LIST STARTED AFTER ID
    labels = title_list[element_index_start_without_id:]

    # tempelary lists and values
    updated_row = []
    temp_list = []
    counter = 0
    ifWrong = True

    # Main loop
    for row in table:
        # checking is a our ID
        if row[element_index_id] == id_[element_index_id]:
            # if not this loop stat error
            ifWrong = False
            updated_row.append(id_[element_index_id])
            temp_list = ui.get_inputs(labels, "Please put new data:")
            # Checking module
            for rec in temp_list:
                updated_row.append(rec)
            table[counter] = updated_row
        counter += 1
    # Error mesage
    if ifWrong == True:
        ui.print_error_message("Id doesn't exist")

    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