Skip to content

Instantly share code, notes, and snippets.

@azukacchi
Created August 24, 2020 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azukacchi/0263fcc20f2a0ce8ba6ed06bdcffedcf to your computer and use it in GitHub Desktop.
Save azukacchi/0263fcc20f2a0ce8ba6ed06bdcffedcf to your computer and use it in GitHub Desktop.
block (or mute) retweeters of a tweet! if you wish to not ever engage in or encounter an unreasonable conversation on twitter with people who interact with a certain tweet
import tweepy
import re
import time
## You should already have a Twitter developer account first
## with Read and Write permission
consumer_key = "YOUR KEY HERE"
consumer_secret = "YOUR KEY HERE"
access_token = "YOUR KEY HERE"
access_token_secret = "YOUR KEY HERE"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
twtlink = 'PASTE THE TWEET LINK WHICH RETWEETERS YOU WANT TO BLOCK' # paste inside the ' '
regex = r'(?=twitter\.com\/(\w+)\/status\/(\d+))'
twtid = int(re.search(regex, twtlink).group(2))
user_name = re.search(regex, twtlink).group(1)
rtid = api.retweeters(twtid)
for id in rtid:
api.create_block(id=id)
#api.create_mute(id=id) IF YOU WANT TO ONLY MUTE THEM
time.sleep(3)
api.create_block(screen_name=user_name)
print(f"Number of people who retweeted the tweets that you've blocked: {len(rtid)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment