def _autofollow(api, action, dry_run):
try:<EOL><INDENT>followers = api.followers_ids()<EOL>friends = api.friends_ids()<EOL><DEDENT>except TweepError as e:<EOL><INDENT>api.logger.error('<STR_LIT>', action)<EOL>api.logger.error("<STR_LIT:%s>", e)<EOL>return<EOL><DEDENT>if action == "<STR_LIT>":<EOL><INDENT>method = api.destroy_friendship<EOL>independent, dependent = followers, friends<EOL><DEDENT>elif action == "<STR_LIT>":<EOL><INDENT>method = api.create_friendship<EOL>independent, dependent = friends, followers<EOL><DEDENT>else:<EOL><INDENT>raise IndexError("<STR_LIT>".format(action))<EOL><DEDENT>api.logger.info('<STR_LIT>', action, len(friends), len(followers))<EOL>targets = [x for x in dependent if x not in independent]<EOL>for uid in targets:<EOL><INDENT>try:<EOL><INDENT>api.logger.info('<STR_LIT>', action, uid)<EOL>if not dry_run:<EOL><INDENT>method(id=uid)<EOL><DEDENT><DEDENT>except RateLimitError:<EOL><INDENT>api.logger.warning("<STR_LIT>", RATE_LIMIT_RESET_MINUTES)<EOL>sleep(RATE_LIMIT_RESET_MINUTES * <NUM_LIT>)<EOL>method(id=uid)<EOL><DEDENT>except TweepError as e:<EOL><INDENT>api.logger.error('<STR_LIT>', action, uid)<EOL>api.logger.error("<STR_LIT>", e.api_code, e)<EOL><DEDENT><DEDENT>
Follow back or unfollow the friends/followers of user authenicated in 'api'.
:api twitter_bot_utils.api.API
:dry_run bool don't actually (un)follow, just report