Skip to content

Instantly share code, notes, and snippets.

@SamadiPour
Created July 31, 2022 22:30
Show Gist options
  • Save SamadiPour/3ba6059aab311805cf3ef04935ffb457 to your computer and use it in GitHub Desktop.
Save SamadiPour/3ba6059aab311805cf3ef04935ffb457 to your computer and use it in GitHub Desktop.
Twitter user likes and retweets (BlockList)
import tweepy
import os
import json
client = tweepy.Client(
'TWITTER_KEY',
wait_on_rate_limit=True
)
user_response = client.get_user(username='TWITTER_USERNAME')
tweets = tweepy.Paginator(client.get_users_tweets, id=user_response.data.id, exclude=['retweets', 'replies'],
max_results=100).flatten(100)
users = {}
for tweet in tweets:
likes = tweepy.Paginator(client.get_liking_users, id=tweet.id).flatten()
for like in likes:
users[like] = users.get(like, 1) + 1
retweets = tweepy.Paginator(client.get_retweeters, id=tweet.id).flatten()
for retweet in retweets:
users[retweet] = users.get(retweet, 1) + 1
users_list = []
for key, val in sorted(users.items(), key=lambda kv: kv[1]):
key.data['effect'] = val
users_list.append(key.data)
with open('block_list.json', 'w') as fp:
json.dump(users_list, fp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment