DEV Community

Cover image for Twitter Bot
Jeffery Osei
Jeffery Osei

Posted on

Twitter Bot

In this module we will learn how to run a simple python based script for micro-managing a twitter account by replying to mentions, liking and retweeting timeline tweets, updating the user timeline, following to gain more traction and follow backs in a short period of time, super cool!


1. Clone Repo :

Ok so let's begin this awesome journey by clicking here, which will redirect you to the master tree for the python scripts, feel free to use any tool you want to clone or simply click on the download button or you can copy the git clone url and use the git clone {repo_url} command if you feeling fancy.

2. Install Python :

Now in order to run the script, you need to install PYTHON-3.7 for your environment, a simple google search will help you get the file and install process. After you are done run these two commands respectively in your terminal or command prompt

python3 --version && pip3 --version

this will print the python version and the python package manager versions respectively. Cool!

3. Create Twitter Account :

Since you might be testing, simply goto Twitter and create a test account, after that also visit Twitter Developers and sign up for a developer account. Now you might be required to verify your email or phone number, just go through with it. Upon completion, goto the dashboard and point your cursor the top right corner, hover over the links and find the Apps option, click on that and create an app, also go through the requirements like you did before. That's all, that was a long one! LOL... anyway please keep the browser tab open, we will be back for some keys.

4. Install Script Packages :

The script you just cloned needs a couple of other packages to run smoothly, so simply change directory into the folder from your terminal and run this command

pip3 install -r requirements.txt

This will get and install everything for you. Finally something simple!

5. Add Keys :

n this step, we will add in our twitter and news api keys, so head to the cloned folder and open the file up in your favourite editor. Now goto to your twitter developer dashboard and click on your app then select the Access Tokens tab, you wouldn't have the access keys generated for you so click on the generate button to get one. Now in the file you would see the labels for each key in there, simply copy and paste them respectively. Now for the NewsAPI key, head to the news api tab in your browser and copy your api_key in your account page and paste it at the NEWS_API label in the file. For the last two labels feel free to add in any hash tags you prefer and the script will use it to gain its traction. That's all for the file. Hurraay!!!

6. Run Now! :

So excited!, now let's run what we've been waiting for, simply change directory into the cloned folder if you have not done that already and run this command


this will boot up the bot and start printing what it is up to on the terminal to keep you informed, now goto you twitter account watch as the magic you just setup happens!.

7. Run After Restart :

This is very easy to do, simply change directory into the cloned folder above and run this command


and that's it, it will boot up and start automating. Enjoy!

8. Error Logs :

Great!, you are all done and probably smiling at your twitter timeline and followers updating automagically. Anyway if you have or faced any issues following the steps above that you cannot fix, no worries, e-mail me or visit my website and please remember to be thorough in telling me exactly what went wrong, thanks for your time, Happy Automating!

Code Repo:

GitHub logo Open-Clonne / scripts

All scripts for automation purposes

Top comments (0)