def __init__(self, my_username, args): db_models.init() self._reset_state() if my_username is None: print(COLOR_FAIL + "No username, so the script won't read/write from the database" + COLOR_ENDC) return global IS_USING_DATABASE IS_USING_DATABASE = True self.profile = get_ig_profile_by_profile_name(my_username) scrape_for_account = args.__dict__.get('scrape_for_account', []) self.scrape_for_account_list = scrape_for_account if isinstance(scrape_for_account, list) else [scrape_for_account] if args.reinteract_after is not None: self.reinteract_after = get_value(args.reinteract_after, "Re-interact after {} hours", 168) if args.refilter_after is not None: self.refilter_after = get_value(args.refilter_after, "Re-filter after {} hours", 168) if args.recheck_follow_status_after is not None: self.recheck_follow_status_after = get_value(args.recheck_follow_status_after, "Re-check follow status after {} hours", 168) self.profiles_targets_list_from_parameters = args.__dict__.get('targets_list', []) self.url_targets_list_from_parameters = args.__dict__.get('posts_urls_list', []) whitelist_from_parameters = args.__dict__.get('whitelist_profiles', None) blacklist_from_parameters = args.__dict__.get('blacklist_profiles', None) # Whitelist and Blacklist try: with open(FILENAME_WHITELIST, encoding="utf-8") as file: self.whitelist = [line.rstrip() for line in file] except FileNotFoundError: print_debug("No whitelist provided") try: with open(FILENAME_BLACKLIST, encoding="utf-8") as file: self.blacklist = [line.rstrip() for line in file] except FileNotFoundError: print_debug("No blacklist provided") if whitelist_from_parameters is not None: if isinstance(whitelist_from_parameters, list) and len(whitelist_from_parameters) > 0: print("Loading whitelist from profiles_whitelist parameter...") self.whitelist.extend(whitelist_from_parameters) if blacklist_from_parameters is not None: if isinstance(blacklist_from_parameters, list) and len(blacklist_from_parameters) > 0: print("Loading blacklist from profiles_blacklist parameter...") self.blacklist.extend(blacklist_from_parameters) # Print meta data if len(self.profiles_targets_list_from_parameters) > 0 or len(self.url_targets_list_from_parameters) > 0: count = len(self.profiles_targets_list_from_parameters) + len(self.url_targets_list_from_parameters) print(f"Profiles and posts to interact from args: {count}") count_from_file = self._count_targets_from_file() if count_from_file > 0: print(f"Profiles and posts to interact from targets file: {count_from_file}") count_from_scrapping = self.profile.count_scrapped_profiles_for_interaction() if count_from_scrapping > 0: print(f"Profiles to interact from scrapping: {count_from_scrapping}")
def _run_inside_session(self, username, action): print(f"Starting session for {username}") profile = get_ig_profile_by_profile_name(username) session_id = profile.start_session(None, "", "", ProfileStatus.VALID, 2200, 500) print(f"session_id = {session_id}") action(profile, session_id) print(f"Ending session for {username}") profile.end_session(session_id)