Skip to content

Instantly share code, notes, and snippets.

@Ara4Sh
Created March 20, 2022 17:24
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 Ara4Sh/c85e6aebecef86a2df1ceec616acb905 to your computer and use it in GitHub Desktop.
Save Ara4Sh/c85e6aebecef86a2df1ceec616acb905 to your computer and use it in GitHub Desktop.
Simple python script to remove twitter likes.
#!/usr/bin/env python3
"""
Remove likes (favorite) from your tweets using twitter API
you need to install twitter-client for python to use this code:
pip install python-twitter ( more info https://github.com/bear/python-twitter)
to use this you need to generate authntication tokens for your account
find more info on (https://developer.twitter.com/en/docs/basics/authentication/guides/access-tokens)
"""
import asyncio
import concurrent.futures
import twitter
NUMBER_OF_TWEETS = 1000
WORKERS = 2
twitter_api_client = twitter.Api(
consumer_key='CONSUMER_KEY',
consumer_secret='CONSUMER_SECRET',
access_token_key='ACCESS_TOKEN_KEY',
access_token_secret='ACCESS_TOKEN_SECRET'
)
def remove_tweet(tweet_id):
"""
destroy favorite using twitter API
:param tweet_id: status_id of tweet (string)
:return: None
"""
try:
twitter_api_client.DestroyFavorite(status_id=tweet_id)
print('removed fav from %s' % tweet_id)
except twitter.TwitterError as e:
print('problem with removing Fav from %s' % tweet_id)
print(e)
# Get list of favorited(liked) tweets
liked_tweets = twitter_api_client.GetFavorites(count=NUMBER_OF_TWEETS)
print('liked tweets count: %s' % len(liked_tweets))
async def main():
loop = asyncio.get_event_loop()
with concurrent.futures.ThreadPoolExecutor(
max_workers=WORKERS) as executor:
futures = [
loop.run_in_executor(
executor,
remove_tweet,
tweet.id
)
for tweet in liked_tweets
]
await asyncio.gather(*futures)
event_loop = asyncio.get_event_loop()
event_loop.run_until_complete(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment