Created
April 12, 2021 19:31
-
-
Save tveastman/7c8ab63d43b68b3b9a0689e1f3e14f3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, argparse, twitter | |
parser = argparse.ArgumentParser() | |
parser.add_argument('screen_name') | |
args = parser.parse_args() | |
api = twitter.Api( # oauth credentials | |
os.environ['CONSUMER_KEY'], os.environ['CONSUMER_SECRET'], | |
os.environ['ACCESS_TOKEN_KEY'], os.environ['ACCESS_TOKEN_SECRET'], | |
sleep_on_rate_limit=True # just pause execution | |
) | |
cursor = -1 | |
while cursor: | |
next, prev, data = api.GetFollowerIDsPaged( # Fetch page of followers | |
screen_name=args.screen_name, cursor=cursor | |
) | |
cursor = next | |
for user_id in data: | |
result = api.CreateBlock(user_id=user_id) # Send block request | |
print(f"Blocked {result.name} (@{result.screen_name})") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet relies on this library for the Twitter stuff: https://python-twitter.readthedocs.io/en/latest/