Write a Twitter Bot with Python tweepy to Unfollow Non-Followers from the Command Line

00:56:00 0 Comments

What do you call those people who don’t follow you back on Twitter? Celebrities? News outlets? Using the Python tweepy library, we will write a bot to easily unfollow non-followers from the command line.
First, log in to http://dev.twitter.com and create a new application.
The create a file, keys.py , and fill it in with the appropriate information:
Now create a file, unfollow.py , and add the following(pun intended):
To run it from the command line:
You will be prompted to unfollow the non-followers you are currently following. Goodbye, parasites!
Let’s step through it.
The first few blocks should be familiar to you by now: we import tweepy, our keys, and connect to the Twitter API. In the next two blocks perform a similar role, we create lists, and populate them with followers and friends.
Next, we iterate over  friends  and use an if statement to check whether or not each element of friends is in followers . Before we destroy the friendship, we ask for verification.
It’s a simple matter of setting this up to run automatically with a cron job. That’s against Twitter’s Best Practices, so I’ll leave you to figure it out for yourself.

0 comments :