Created
May 11, 2020 11:18
-
-
Save Ara4Sh/1276c7e366ecc3b8031bce1c17de5c95 to your computer and use it in GitHub Desktop.
remove tweets
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
#!/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_secret='', | |
access_token_key='', | |
access_token_secret='', | |
sleep_on_rate_limit=True | |
) | |
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 | |
try: | |
liked_tweets = twitter_api_client.GetFavorites(count=NUMBER_OF_TWEETS,since_id=941621496337846272) | |
print(liked_tweets) | |
except twitter.TwitterError as e: | |
print('problem with removing Fav from %s' % tweet_id) | |
print(e) | |
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