Last active
March 30, 2024 09:13
-
-
Save codingmickey/b3f26cc35c6beb01082c5b58a1ec01c8 to your computer and use it in GitHub Desktop.
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
# | |
# Before running just install the tweepy package via | |
# | |
# pip install tweepy | |
# | |
# And then run via | |
# | |
# python harsh-twitter.py | |
# | |
# WITH THE PROPER CREDENTIALS!!! | |
# | |
# :D | |
# | |
import tweepy | |
# Twitter API credentials | |
consumer_key = 'YOUR_CONSUMER_KEY' | |
consumer_secret = 'YOUR_CONSUMER_SECRET' | |
access_token = 'YOUR_ACCESS_TOKEN' | |
access_token_secret = 'YOUR_ACCESS_TOKEN_SECRET' | |
# Authenticate with Twitter API | |
auth = tweepy.OAuth1UserHandler(consumer_key, consumer_secret, access_token, access_token_secret) | |
api = tweepy.API(auth) | |
# Get your Twitter user ID | |
user_id = api.verify_credentials().id | |
# Get followers and following lists | |
followers = set(api.get_follower_ids(user_id)) | |
following = set(api.get_friend_ids(user_id)) | |
# Identify users who don't follow you back | |
not_following_back = following - followers | |
# Create a private list (if not already created) | |
list_name = 'Not Following Back' | |
private_list = api.create_list(name=list_name, mode='private') | |
# Add users not following back to the private list | |
for user_id in not_following_back: | |
try: | |
api.add_list_member(list_id=private_list.id, user_id=user_id) | |
except tweepy.TweepError as e: | |
print(f'Error adding user to list: {e}') | |
# Unfollow users not following you back | |
for user_id in not_following_back: | |
try: | |
api.destroy_friendship(user_id) | |
except tweepy.TweepError as e: | |
print(f'Error unfollowing user: {e}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment