Ejemplo n.º 1
0
def main():
    connection = init_database()

    show_list = get_show_list(connection)

    # check to see if the list has been modified, and needs to be saved.
    modify_check_list = deepcopy(show_list)

    if show_list is None:
        show_list = ShowList()

    # remove the name of the script from arguments
    args = sys.argv
    args.remove(sys.argv[0])

    entered_arg_loop = False

    for arg in args:
        entered_arg_loop = True
        arg = arg.lower()

        if arg == "add_show":
            show_list.add_show()

        elif arg == "remove_show":
            confirmation = show_list.remove_show(CLI.request_show_name())
            CLI.action_confirmation(confirmation, "show removal")

        elif arg == "get_show":
            requested_show_with_index = show_list.find_show(
                CLI.request_show_name())

            if requested_show_with_index is not None:
                CLI.pretty_print_show(requested_show_with_index.show)

            else:
                print("Entered Show does not exist.")

        elif arg == "get_all_shows":
            for show in show_list.shows:
                CLI.pretty_print_show(show)

        elif arg == "increment_show_episode":
            confirmation = show_list.increment_show(CLI.request_show_name())
            CLI.action_confirmation(confirmation, "incrementing episode")

        elif arg == "increment_show_season":
            confirmation = show_list.increment_show_season(
                CLI.request_show_name())
            CLI.action_confirmation(confirmation, "incrementing season")

        else:
            CLI.help_input()

    if not entered_arg_loop:
        CLI.help_input()

    if not show_list == modify_check_list:
        save_show_list(connection, show_list)

    connection.close()