Beispiel #1
0
def save_raport(data):
    if_want_save = 0
    display.print_message("Do you want to save this raport? Press 1 to save: ")
    if_want_save = common.get_decision_input(if_want_save)
    if if_want_save == 1:
        filename = input("Enter filename: ")
        data_manager.data_export(data, filename + "_raport.txt")
Beispiel #2
0
def get_input_number(label):
    numbers = [1, 2]
    while True:
        try:
            number = int(input(label))
            if number not in numbers:
                raise ValueError
        except ValueError:
            display.print_message("Wrong number")
        else:
            return number
Beispiel #3
0
def edit_category():
    decision = 0
    while decision != 3:
        display.print_message("Edit categories")
        menu = ['Add category', 'Delete category', 'Return ']
        display.print_menu(menu)
        decision = common.get_decision_input(decision)
        if decision == 1:
            add_category()
        elif decision == 2:
            remove_category()
Beispiel #4
0
def config(cat_income, cat_expenses):
    decision = 0
    while decision != 3:
        display.print_message("Configuration menu")
        menu = ['Incomes', 'Expenses', 'Back to main menu']
        display.print_menu(menu)
        decision = common.get_decision_input(decision)
        if decision == 1:
            cat_income = what_to_do(cat_income)
        elif decision == 2:
            cat_expenses = what_to_do(cat_expenses)
    return cat_income, cat_expenses
Beispiel #5
0
def check_guessed_word(word, hide_word):
    """This function checks guessed word
    Args:
        word as string
        hidden word as string
    Returns:
        True or False
    """
    if check_win_condition(word, hide_word):
        return True
    else:
        display.print_message("You are wrong. This word : {}".format(word))
        display.print_message("GAME OVER")
        return False
Beispiel #6
0
def check_win_condition(word, hide_word):
    """This function checks win conditions
    compares words
    Args:
        word as string
        hidden word as string
    Returns:
        True or False
    """
    if word == hide_word:
        display.print_word(hide_word)
        display.print_message("YOU WIN!")
        return True
    return False
Beispiel #7
0
def gen_raport(income, expenses):
    decision = 0
    while decision != 3:
        display.print_message("Generating raport menu")
        menu = ['Incomes', 'Expenses', 'Back to raports menu']
        display.print_menu(menu)
        decision = common.get_decision_input(decision)

        if decision == 1:
            data = common.sort(income)
            display.print_table(data)
            save_raport(data)
        elif decision == 2:
            data = common.sort(expenses)
            display.print_table(data)
            save_raport(data)
Beispiel #8
0
def what_to_do(category):
    decision = 0
    table = []
    while decision != 4:
        display.print_message("What you want to do?")
        menu = [
            'Show categories', 'Add category', 'Remove category',
            'Back to configuration menu'
        ]
        display.print_menu(menu)
        decision = common.get_decision_input(decision)
        if decision == 1:
            for element in category:
                print(element)
        elif decision == 2:
            category = add_category(category)
        elif decision == 3:
            category = remove_category(category)
    return category
Beispiel #9
0
def import_data(filename):
    """
    Import data from a file to a list. 
    :param str filename: optional, name of the file to be imported
    :returns: list representing data
    :rtype: list
    """
    result = []
    try:
        with open(filename, 'r') as datafile:
            for line in datafile.readlines():
                result.append(line.strip().split(','))
    except FileNotFoundError:
        message = "FileNotFoundError"
        display.print_message(message)
    except Exception:
        message = "Unknown error"
        display.print_message(message)
    else:
        return result
Beispiel #10
0
def main():
    expenses = data_manager.data_import('expenses.txt')
    incomes = data_manager.data_import('earnings.txt')
    income_categories = income_expenses.get_category('income_categories.txt')
    expense_categories = income_expenses.get_category('categories.txt')

    os.system('clear')
    decision = 0


    while decision != 5:
        os.system('clear')
        display.print_message(intro.intro)
        display.print_message(intro.intro2)
        display.print_message("Main menu")
        menu = ['Expenses', 'Incomes', 'Raports', 'Categories configuration', 'Exit']  # main menu
        display.print_menu(menu)
        decision = common.get_decision_input(decision)
        os.system('clear')
        if decision == 1:
            income_expenses.expenses(expenses, expense_categories)
        elif decision == 2:
            income_expenses.incomes(incomes, income_categories)
        elif decision == 3:
            raport(incomes, expenses)
        elif decision == 4:
            config(income_categories, expense_categories)

    income_categories = common.prepare_list_to_save(income_categories)
    expense_categories = common.prepare_list_to_save(expense_categories)

    data_manager.data_export(expenses, 'expenses.txt')
    data_manager.data_export(incomes, 'earnings.txt')
    data_manager.data_export(income_categories, 'income_categories.txt')
    data_manager.data_export(expense_categories, 'categories.txt')
Beispiel #11
0
def raport(income, expenses):
    decision = 0
    while decision != 5:
        display.print_message("Raports menu")
        menu = [
            'Generate raport', 'Show raports', 'Show specified raport',
            'Delete raports', 'Back to main menu'
        ]
        display.print_menu(menu)
        decision = common.get_decision_input(decision)
        if decision == 1:
            gen_raport(income, expenses)
        elif decision == 2:
            data = get_list_raport()
            display.print_list(data, 'Files: \n')
        elif decision == 3:
            data = get_list_raport()
            filename = validate_filename(data)
            show_raport(filename)
        elif decision == 4:
            data = get_list_raport()
            filename = validate_filename(data)
            delete_raport(filename)
Beispiel #12
0
def game_over_condition(life):
    """This function checks game over
    conditions and displays hidden word.
    Args:
        life as number
    Returns:
        None
    """
    if life == 0:
        display.print_message("Life : {}".format(life))
        display.print_message("Guessed  word : {}".format(word))
        display.print_message("GAME OVER")
Beispiel #13
0
def get_letter_from_user(wrong_letters, hide_word):
    """This function gets letter from user    
    Args:
        wrong_letters as list
        hidden word as string
    Returns:
        letter as string
    """
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    while True:
        guess = inputs.get_input_string("Please enter a letter ").lower()
        if len(guess) != 1:
            display.print_message("There must be single letter")
        elif guess in wrong_letters:
            display.print_message(
                "You have already tried this letter. Choose again")
        elif guess in hide_word:
            display.print_message(
                "You have already guessed this letter. Choose again")
        elif guess not in alphabet:
            display.print_message("This is not a LETTER")
        else:
            return guess
Beispiel #14
0
def show_raport(filename):
    if filename:
        data = data_manager.data_import(filename)
        display.print_table(data)
    else:
        display.print_message("No such file!")
Beispiel #15
0
def delete_raport(filename):
    if filename:
        os.remove(filename)
        display.print_message("Raport " + filename + " removed!")
    else:
        display.print_message("No such file!")