Example #1
0
def profile_menu(login):
    print('logged as: ' + login)
    menu_commands = [
        'Show my gallery', 'Generate new art', 'Rate paintings',
        'Save your changes & logout'
    ]
    index_ = 0
    i = 0
    logged_in = True
    while logged_in:
        print_magic_menu(menu_commands, index_, 'logged as: ' + login)
        index_, choice = get_input(index_, menu_commands)
        if index_ == 0 and choice == 1:
            if os.path.isfile("profiles/" + login + '.json'):
                picture = data_manager.import_from_file(login)
                pictures.display_gallery(picture)
                input("Press Enter to continue...")
            else:
                print('Your gallery is empty')
                input("Press Enter to continue...")

        if index_ == 1 and choice == 1:
            picture = pictures.generate_picture()
            pictures.display_picture(picture)
            choose_picture(login, picture)
        if index_ == 2 and choice == 1:
            picture = rating_pictures()
            gallery_ = grade_picture(picture)
            data_manager.export_to_file(login, gallery_)
        if index_ == 3 and choice == 1:
            logged_in = False
def change_colors(option, color, colors_list_for_user):
    color_proportions = data_manager.import_from_file("proportions")
    color_list = get_colors_data()
    color_to_change = color_list[color]

    if option == 1:
        color_proportions = list(
            filter(lambda a: a != color_to_change, color_proportions))
        colors_list_for_user.remove(colors_list_for_user[color])

    elif option == 2:
        color_proportions.append(color_to_change)

    elif option == 3:
        X = len(color_list)
        Y = len(color_proportions)
        index = random.randint(X, Y)
        for i in range(index):
            color_proportions.insert(Y, color_to_change)

    elif option == 4:
        for color_to_change in color_proportions:
            index = random.randint(0, 1)
            if index == 1:
                color_proportions.remove(color_to_change)

    data_manager.export_to_file("proportions", color_proportions, "w")

    return colors_list_for_user
Example #3
0
    def test_export_to_file(self):
        import os
        tmp_filename = 'test_data_tmp.txt'
        data_manager.export_to_file(tmp_filename, self.test_list)
        are_identical = compare_file_contents(self.test_filename, tmp_filename)
        os.remove(tmp_filename)

        self.assertTrue(are_identical)
def get_random_proportion():

    colors_list = get_colors_data()

    colors_dict = {}

    for color in colors_list:
        value = random.randint(1, 5)
        if color not in colors_dict:
            colors_dict[color] = value

    proportion_list = []

    for key, value in colors_dict.items():
        proportion = [key] * value
        proportion_list.extend(proportion)

    data_manager.export_to_file("proportions", proportion_list, "w")

    return proportion_list
Example #5
0
def choose():
    myfile = "position/positions.txt"
    option = ui.get_inputs("\nPlease enter a number: ")
    table = data_manager.imports_from_file(myfile)
    if option == "1":
        ui.clear()
        data_manager.export_to_file(myfile, create_position(table))
    elif option == "2":
        ui.clear()
        idx = ui.get_inputs("Enter the position ID: ")
        if common.check_valid_id(table, idx) == False:
            ui.clear()
            ui.print_error(f"Invalid position ID! ('{idx}')")
        else:
            ui.print_result(
                get_applied_students(read_position(table, idx), idx),
                "Position details")
    elif option == "3":
        ui.clear()
        result = common.read_elements(table)
        if len(result) == 0:
            ui.clear()
            ui.print_error("There are no positions in this list!")
        else:
            show_table(format_seats(result))
    elif option == "4":
        ui.clear()
        idx = ui.get_inputs("Enter position ID: ")
        if common.check_valid_id(table, idx) == False:
            ui.clear()
            ui.print_error(f"Invalid position ID! ('{idx}')")
        else:
            data_manager.export_to_file(
                myfile,
                update_position(
                    table, idx, "description",
                    ui.get_inputs(
                        "Enter the new value of the description.\n")))
    elif option == "5":
        ui.clear()
        idx = ui.get_inputs("Enter position ID: ")
        if common.check_valid_id(table, idx) == False:
            ui.clear()
            ui.print_error(f"Invalid position ID! ('{idx}')")
            return True

        if common.check_data_in_app(idx, "position") == True:
            ui.clear()
            ui.print_error("You cannot delete this position!")
        else:
            data_manager.export_to_file(myfile,
                                        common.delete_element(table, idx))
    elif option == "0":
        ui.clear()
        return False
    else:
        raise KeyError(f"There is no such option. ({option})")
    return True
Example #6
0
def choose_picture(login, picture):
    edit = True
    while edit:
        options = [
            "I want more harmony!", "Give me some chaos!",
            "I need something complately else", "Change coloristics",
            "Turn on sector changing mode", "Turn off sector changing mode",
            "Masterpiece - save!"
        ]
        print_menu(options)
        print("How do you like this picture?\n")
        decision = getch()

        if decision == "1":

            picture = pictures.change_picture(picture, harmony=1)
            pictures.display_picture(picture)

        elif decision == "2":
            percent_of_change = 0.6
            picture = pictures.change_picture(picture, percent_of_change)
            pictures.display_picture(picture)

        elif decision == "3":
            picture = pictures.generate_picture()
            pictures.display_picture(picture)

        elif decision == "4":
            percent_of_change = manipulate_color_menu()
            picture = pictures.change_picture(picture, percent_of_change)
            pictures.display_picture(picture)

        elif decision == "5":
            try:
                sector = int(
                    input(
                        " 1  2  3\n 4  5  6\n 7  8  9\n Choose number of sector you want to change: "
                    ))
            except ValueError:
                print("You entered wrong data")
            temp = picture
            picture, data_list = pictures.choose_sector(temp, sector)
            pictures.display_picture(
                pictures.replace_changed_sector(temp, picture, data_list))

        elif decision == "6":
            try:
                picture = pictures.replace_changed_sector(
                    temp, picture, data_list)
                print("Sector changing mode turned off")
                pictures.display_picture(picture)
            except UnboundLocalError:
                print("You are not in sector changing mode yet ;)")

        elif decision == "7":
            gallery_ = pictures.make_gallery(picture, login)
            data_manager.export_to_file(login, gallery_)
            edit = False
            print("Your picture is saved in gallery")

        elif decision == "q":
            sys.exit()
Example #7
0
def choose():
    myfile = "student/students.txt"
    option = ui.get_inputs("\nPlease enter a number: ")
    table = data_manager.imports_from_file(myfile)
    if option == "1":
        ui.clear()
        data_manager.export_to_file(myfile, create_student(table))
    elif option == "2":
        ui.clear()
        idx = ui.get_inputs("Enter the student ID: ")
        if common.check_valid_id(table, idx) == False:
            ui.clear()
            ui.print_error(f"Invalid student ID! ('{idx}')")
        else:
            result = get_student_applications(idx, read_student(table, idx))
            ui.print_result(result, "Student details")
    elif option == "3":
        ui.clear()
        result = read_students(table)
        if len(result) == 0:
            ui.clear()
            ui.print_error("There are no students in this list!")
        else:
            show_table(result)
    elif option == "4":
        ui.clear()
        attributes = ["name", "age", "status"]
        idx = ui.get_inputs("Enter student ID: ")
        if common.check_valid_id(table, idx) == False:
            ui.clear()
            ui.print_error(f"Invalid student ID! ('{idx}')")
            return True
        update = ui.get_inputs("Which attribute do you want to change?\n")
        update = update.lower()
        if update not in attributes:
            ui.clear()
            ui.print_error(f"You cannot change this attribute! ('{update}')")
        else:
            data_manager.export_to_file(
                myfile,
                update_student(
                    table, idx, update,
                    ui.get_inputs(f"Enter the new value of the {update}.\n")))
    elif option == "5":
        ui.clear()
        idx = ui.get_inputs("Enter student ID: ")
        if common.check_valid_id(table, idx) == False:
            ui.clear()
            ui.print_error(f"Invalid student ID! ('{idx}')")
        else:
            data_manager.export_to_file(
                myfile,
                update_student(table, idx, "status",
                               get_new_status(table, idx)))
    elif option == "6":
        ui.clear()
        idx = ui.get_inputs("Enter student ID: ")
        if common.check_valid_id(table, idx) == False:
            ui.clear()
            ui.print_error(f"Invalid student ID! ('{idx}')")
            return True

        if common.check_data_in_app(idx, "student") == True:
            ui.clear()
            ui.print_error("You cannot delete this student!")
        else:
            data_manager.export_to_file(myfile,
                                        common.delete_element(table, idx))
    elif option == "0":
        ui.clear()
        return False
    else:
        raise KeyError(f"There is no such option. ({option})")
    return True
Example #8
0
def choose():
    myfile = "application/applications.txt"
    option = ui.get_inputs("\nPlease enter a number: ")
    table = data_manager.imports_from_file(myfile)
    if option == "1":
        ui.clear()
        pos_name = ui.get_inputs("Enter a position name to apply: ")
        positions = data_manager.imports_from_file("position/positions.txt")
        student_id = ui.get_inputs("Enter a student id to apply: ")
        students = data_manager.imports_from_file("student/students.txt")
        opt = ui.get_inputs("Enter the status(applied/not applied): ")
        if common.check_valid_id(positions,
                                 pos_name) == False or common.check_valid_id(
                                     students, student_id) == False:
            ui.clear()
            ui.print_error("Non existing position or student!")
        else:
            if opt != "applied" and opt != "not applied":
                ui.clear()
                ui.print_error("Thats not an option")
            else:
                data_manager.export_to_file(
                    myfile,
                    create_applicaion(table, opt, pos_name, student_id,
                                      positions))
    elif option == "2":  ##Update Applications
        ui.clear()
        idx = ui.get_inputs("Enter application ID: ")
        if common.check_valid_id(table, idx) == False:
            ui.clear()
            ui.print_error(f"Invalid application ID! ('{idx}')")
            return True
        else:
            if common.check_if_applied(table, idx) == True:
                ui.clear()
                ui.print_error("You cant modify not applied status")
            else:
                for row in table:
                    if row[0] == idx:
                        row[1] = "not applied"
                data_manager.export_to_file(myfile, table)
    elif option == "3":
        ui.clear()
        idx = ui.get_inputs("Enter application ID: ")
        if common.check_valid_id(table, idx) == False:
            ui.clear()
            ui.print_error(f"Invalid application ID! ('{idx}')")
        else:
            data_manager.export_to_file(myfile,
                                        common.delete_element(table, idx))
    elif option == "4":
        ui.clear()
        result = common.read_elements(table)
        if len(result) == 0:
            ui.clear()
            ui.print_error("There are no application in this list!")
        else:
            show_table(result)
    elif option == "0":
        ui.clear()
        return False
    else:
        raise KeyError(f"There is no such option. ({option})")
    return True