Last active
August 24, 2020 11:48
-
-
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
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 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