Skip to content

Instantly share code, notes, and snippets.

@tveastman
Created April 12, 2021 19:31
Show Gist options
  • Save tveastman/7c8ab63d43b68b3b9a0689e1f3e14f3e to your computer and use it in GitHub Desktop.
Save tveastman/7c8ab63d43b68b3b9a0689e1f3e14f3e to your computer and use it in GitHub Desktop.
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})")
@tveastman
Copy link
Author

tveastman commented Apr 12, 2021

This snippet relies on this library for the Twitter stuff: https://python-twitter.readthedocs.io/en/latest/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment