def unfollow(instagram: Instagram, utils: Utils, pending_unfollows: dict) -> None: """Takes a dict of users and gets the accounts to unfollow using selenium webdriver""" unfollow_left = pending_unfollows[instagram.username] for i in range(len(unfollow_left)): user = unfollow_left.pop() try: link = instagram.create_link(user) instagram.unfollow(link) seconds = random.randint(15, 30) time.sleep(seconds) except KeyboardInterrupt: pending_unfollows[instagram.username] = unfollow_left save_users_left(instagram, utils, pending_unfollows, config.UNFOLLOW_LEFT_PATH) close(instagram) except Exception as e: print(f"Following error appear when visiting {user}:\n{e}") seconds = random.randint(5, 10) time.sleep(seconds) continue if (i + 1) % 10 == 0: print(f"You have unfollowed {i+1} accounts")
pending_unfollows = get_users_left(instagram, utils, config.UNFOLLOW_LEFT_PATH) pending_users_left = check_pending_tasks(instagram, utils, pending_unfollows, pending_users_left) if not pending_users_left: pending_users_left = new_session(instagram, utils) # Get users left for current session users_left = pending_users_left[instagram.username] for i in range(len(users_left)): user = users_left.pop() link = instagram.create_link(user) need_follow = instagram.already_follow(link) try: if need_follow and config.LIKE_PHOTOS: photos = instagram.get_photos(link) like_comment_photos(instagram, utils, photos, user, config.COMMENT_PHOTOS) if photos and config.FOLLOW: instagram.follow(link) seconds = random.randint(45, 90) time.sleep(seconds) else: