Skip to content

Instantly share code, notes, and snippets.

@azukacchi
Last active August 24, 2020 11:48
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/99ab7cda0871c6719f5e33bd351ecfb1 to your computer and use it in GitHub Desktop.
Save azukacchi/99ab7cda0871c6719f5e33bd351ecfb1 to your computer and use it in GitHub Desktop.
block all fancams under a tweet! a python script to help block fancams under any tweet without blocking other conversations
import tweepy
import re
import time
## You should already have a Twitter developer account first
consumer_key = "YOUR CONSUMER KEY HERE"
consumer_secret = "YOUR CONSUMER SECRET HERE"
access_token = "YOUR ACCESS TOKEN HERE"
access_token_secret = "YOUR ACCESS TOKEN SECRET"
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 = '' # put the link of the tweet under which you want to block all the replies with fancam, place 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)
tweets = tweepy.Cursor(api.search, q='to:{} filter:replies'.format(user_name), tweet_mode='extended', since_id=twtid).items()
items = []
blocklist = []
username = set()
for tweet in tweets:
if not hasattr(tweet,'in_reply_to_status_id'):
continue
if tweet.in_reply_to_status_id == twtid:
items.append(tweet.id)
username.add(tweet.user.id)
if not hasattr(tweet, 'extended_entities'):
continue
elif tweet.extended_entities['media'][0]['type'] == 'video':
api.create_block(id=tweet.user.id)
time.sleep(10)
blocklist.append(tweet.id)
print(f'Number of all reply under the status: {len(items)}')
print(f'Number of people replying under the status: {len(username)}')
print(f'Number of reply under the status with fancam: {len(blocklist)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment