Twitter Like and Retweet Bot

A Twitter bot written in Python using Tweepy and hosted on a server. It will like and/or retweet tweets that contain single or multiple keywords and hashtags.


  1. Apply for Twitter Developer Access with the account you want the bot to be used for.

  2. Create a new Twitter Application to generate your private keys, secrets, and tokens.


  • Make sure the app settings has Read and Write permissions.


  1. Create a file named to hold the private information using the format below.
    • See File Structure for where the file should be placed.
  1. Adjustments you can make in to tweak the bot to your liking. (Keep in mind the TwitterAPI search index has a 7-day limit, no tweets will be found for a date older than one week.)

    • search_keywords - Keyword(s) and/or hashtag(s) that you want to retweet
    • delay - Time to wait between processing requests in seconds
    • result_type - Specify what type of search results you want to get
      • "recent", "popular", or "mixed"
    • number_of_tweets - Specify the number of tweets you want the bot to iterate through
    • run_continuously - Set True if you want the bot to run continuously
      • Also set True if you will be deploying the script
    • retweet_tweets, like_tweets - Adjust booleans for whether you want to only retweet, only like, or do both
  2. Run the script. Enjoy your Twitter bot!


File Structure

 |-- requirements.txt


Here is a tutorial on how to deploy / host the bot on a server.


  1. Create a free Beginner PythonAnywhere account.


  1. Go to Files, create a new Directory, upload the three .py files.

Upload Files

  1. Create a new bash console on your Dashboard and run pip with your python version to install tweepy


pip3.8 install --user tweepy
  1. Copy the file path, go to Tasks, enter the UTC time you want the script to run at, and enter the python version and file path with at the end.
python3.8 /home/account-name/directory-name/	

Schedule Task

  1. After the task runs as the scheduled time, you can check the task log to see the bot running


Amazon Web Services

  1. Launch an EC2 instance on Amazon Web Services.

Launch EC2 Instance

  1. Load the key-pair file (.pem) into PuTTYgen (which was downloaded when you installed PuTTY) and save the private key as a private key file (.ppk).

Generate PPK

  1. Connect to your instance on WinSCP.
    • The host name is [email protected][public DNS here].
    • Click Advanced, go to Authentication under SSH, and load the previously generated private key file (.ppk).
    • Login to the session.

Conenct to WinSCP

  1. Use WinSCP to transfer the project's .py files to the server.

WinSCP File Transfer

  1. Connect to your instance on a bash command line using one of the following ways.
    • Use a bash shell with the example ssh command (I use Git Bash).
      • Make sure you are in the directory with the key-pair file (.pem).
    • Use PuTTY with the public DNS and private key file (.ppk).

Connect to Bash

  1. Install python and pip to the server on the bash command line.
sudo apt update 
sudo apt upgrade
sudo apt install python3
sudo apt install python3-pip
pip3 install update pip
  1. Check if python and pip have been installed correctly.
python3 --version
pip3 --version
  1. Install tweepy to the server.
pip3 install tweepy
  1. Run the script. Enjoy!.
  1. See Additional Information for details on running the script continuously.
    • I used the screen option.