Esempio n. 1
0
def core():
    # Config
    parse_args()
    create_config_if_not_exist()
    init(autoreset=True)
    clear_screen()

    # Header
    header()

    # Get info
    driver = choose_driver()
    username = get_username()
    password = get_password()
    path = get_path()
    start = get_start()
    end = get_end()

    vid_choice = get_video_choice()

    line()

    # Start Normal Download
    if not args.list:
        t = Turtle()
        t.set_path(path)
        t.set_start(start)
        t.set_end(end)
        t.open(driver)
        sign_result = t.sign_in(username, password)

        line()

        if sign_result:
            # Get user links
            pic_user = input("Username for Photos : ")
            folder_name = input(
                "Folder name (Leave empty for Instagram username) : ")
            link_result = t.get_img_links(pic_user)

            line()
            if link_result:
                # Download pictures
                down_choice, count = get_download_choice()
                t.download_photos(folder_name, down_choice, count, vid_choice)

        t.close()

    # List Download
    else:
        # Get Json list
        json_path = ""
        if os.path.exists(args.list):
            json_path = args.list
        else:
            print_red("Json path does not exist!")
            return False

        # Open Json list
        with open(json_path, encoding="utf-8") as file:
            data = json.load(file)

            # Instance Turtle and start driver
            t = Turtle()
            t.set_path(path)
            t.open(driver)
            sign_result = t.sign_in(username, password)
            line()

            if sign_result:
                report = []

                # pic_user loop start
                for pic_user_item in data:
                    # Get user links
                    link_result = t.get_img_links(pic_user_item[1])
                    line()

                    # Download pictures
                    down_choice, count = get_download_choice()
                    total_download = t.download_photos(pic_user_item[0],
                                                       down_choice, count,
                                                       vid_choice)
                    line()

                    # Add download result to Log file
                    if t.result:
                        t.log.append("### RESULT ### TRUE  ### " +
                                     pic_user_item[0])
                        report.append([pic_user_item[0], True, total_download])
                    else:
                        t.log.append("### RESULT ### FALSE ### " +
                                     pic_user_item[0])
                        report.append(
                            [pic_user_item[0], False, total_download])
                    t.log.append("-------------------------------")

                # Add all user report to Log file
                t.log.append("")
                t.log.append("$$ ALL DOWNLOAD RESULT $$")
                t.log.append("-------------------------")

                table_headers = [
                    Style.BRIGHT + Fore.MAGENTA + "STATUS", "TOTAL DOWNLOAD",
                    "USERNAME"
                ]
                table_content = []

                for item in report:
                    item_color = Fore.GREEN if item[1] else Fore.RED
                    table_content.append([
                        item_color + str(item[1]),
                        str(item[2]),
                        str(item[0])
                    ])

                t.log.append(
                    tabulate(table_content,
                             headers=table_headers,
                             tablefmt="presto",
                             colalign=("center", "center", "center")))

                t.log.append("")

            t.close()
Esempio n. 2
0
def core():
    # Config
    parse_args()
    create_config_if_not_exist()
    init()
    clear_screen()

    # Header
    header()

    # Get info
    driver = choose_driver()
    username = get_username()
    password = get_password()
    path = get_path()
    vid_choice = get_video_choice()

    line()

    # Start Normal Download
    if not args.list:
        t = Turtle()
        t.set_path(path)
        t.open(driver)
        sign_result = t.sign_in(username, password)

        line()

        if sign_result:
            # Get user links
            pic_user = input("Username for Photos : ")
            folder_name = input(
                "Folder name (Leave empty for Instagram username) : ")
            link_result = t.get_img_links(pic_user)

            line()
            if link_result:
                # Download pictures
                down_choice, count = get_download_choice()
                t.download_photos(folder_name, down_choice, count, vid_choice)

        t.close()

    # List Download
    else:
        # Get Json list
        json_path = ""
        if os.path.exists(args.list):
            json_path = args.list
        else:
            print_red("Json path does not exist!")
            return False

        # Open Json list
        with open(json_path, encoding="utf-8") as file:
            data = json.load(file)

            # Instance Turtle and start driver
            t = Turtle()
            t.set_path(path)
            t.open(driver)
            sign_result = t.sign_in(username, password)
            line()

            if sign_result:
                report = []

                # pic_user loop start
                for pic_user_item in data:
                    # Get user links
                    link_result = t.get_img_links(pic_user_item[1])
                    line()

                    # Download pictures
                    down_choice, count = get_download_choice()
                    total_download = t.download_photos(pic_user_item[0],
                                                       down_choice, count,
                                                       vid_choice)
                    line()

                    # Add download result to Log file
                    if t.result:
                        t.log.append("### RESULT ### TRUE  ### " +
                                     pic_user_item[0])
                        report.append([pic_user_item[0], True, total_download])
                    else:
                        t.log.append("### RESULT ### FALSE ### " +
                                     pic_user_item[0])
                        report.append(
                            [pic_user_item[0], False, total_download])
                    t.log.append("-------------------------------")

                # Add all user report to Log file
                t.log.append("$$ ALL DOWNLOAD RESULT $$")
                t.log.append("-------------------------")
                for item in report:
                    t.log.append("$$ " + str(item[1]) +
                                 " $$ Total Download : " + str(item[2]) +
                                 " $$ " + str(item[0]))
                t.log.append("-------------------------")

            t.close()