Creating A TweetBot With Tweepy
If you want to create a twitter bot you can easily with python and tweepy. It takes very little time to get one setup. We will be using two files for this example. Our python file wil be called twitbot.py and our file full of links (or whatever you want to tweet) in our list.txt file in the same directory.
Let’s start this off with our python file named twitbot.py. First of all you need to make sure the tweepy library is installed.
|
|
You will need to import the tweepy, sys, and time libraries in your script.
|
|
After this you need to make sure you have your application setup with your consumer/access keys and consumer/access secret keys. I won’t be going over that unless I get some feedback that someone needs to see it actually done.
|
|
Since you have your keys and secret keys setup you can get on with the next part and that is setting the authentication handler you will use with the library.
|
|
We will give it your access token with this line.
|
|
Now we have the bearer token and ready to go!
|
|
Now we will switch to a file we use to keep a curated list of links with articles or videos I want to share in our twitter bot called list.txt and just have each link a seperate line in the file. Like this:
|
|
Now back to our twitboy.py file. When we run the twitbot.py script we will give it an arguement of the file that has the list of links in it as an arguement like this:
|
|
We have to take the arg in so we know what the file is called
|
|
We have to open the files and read in all of the lines and then close the file too!
|
|
All thats left is to iterate over all the lines we’ve read in and update our status on twitter as well
|
|
And there you have it you can check out the source code at https://github.com/intelwalk/python-twitbot
Thanks for checking this article out!