A Twitter bot written in Python using Tweepy and hosted on a server.

Overview

Twitter Like and Retweet Bot ❤️ 🔁

Version 1.0.0 Python 3.6 | 3.7 | 3.8 Tweepy Version 3.9.0 Open Source? Yes!

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.


Table of Contents


Getting Started

Make sure to follow Twitter's Automation Rules to avoid getting your account banned.

Prerequisites

To Run the Bot

  • Python 3
  • Pip - a python package manager
    • Download this file, open a command prompt and navigate to the folder containing the get-pip.py installer, and run python get-pip.py to install
    • Run pip --version to check if it has installed correctly
  • Tweepy - an easy-to-use python library for accessing Twitter's API
    • Run pip install tweepy

To Host the Bot

Since the TwitterAPI search index can only retrieve tweets posted within the past 7 days, if the hashtags or keywords are not super popular, I would recommend hosting it on PythonAnywhere and scheduling a task to run twitter-bot.py at a certain time everyday, so the script will not just stop when there are no more tweets to process.

Otherwise, you can deploy it on AWS EC2 to run the bot 24/7.

On PythonAnywhere
  • PythonAnywhere - an online integrated development environment and web hosting service based on the Python programming language
On Amazon Web Services
  • Amazon Web Services EC2 - a web service that provides secure, resizable compute capacity in the cloud
  • PuTTY - an open-source terminal emulator, serial console and network file transfer application
  • WinSCP - a client that allows secure file transfers between the client's local computer and the remote server

Instructions

  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.

Keys and Secrets

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

App Permissions

  1. Create a file named credentials.py to hold the private information using the format below.
TWITTER_API_KEY="xxxx"
TWITTER_API_KEY_SECRET="xxxx"
TWITTER_ACCESS_TOKEN="xxxx"
TWITTER_ACCESS_TOKEN_SECRET="xxxx"
  1. Adjustments you can make in config.py 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!

python twitter-bot.py

File Structure

Twitter-Retweet-Bot
 |-- config.py
 |-- credentials.py
 |-- requirements.txt
 |-- twitter-bot.py

Deployment

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

PythonAnywhere

  1. Create a free Beginner PythonAnywhere account.

Create 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

Bash Console

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 twitter-bot.py at the end.
python3.8 /home/account-name/directory-name/twitter-bot.py

Schedule Task

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

Check Logs

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 ubuntu@[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!.
python3 twitter-bot.py
  1. See Additional Information for details on running the script continuously.
    • I used the screen option.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

How To Contribute

  1. Fork the repository to your own Github account.
  2. Clone the project to your machine.
  3. Create a branch locally with a succinct but descriptive name.
  4. Commit changes to the branch.
  5. Following any formatting and testing guidelines specific to this repo.
  6. Push changes to your fork.
  7. Open a Pull Request in my repository.

Creator / Maintainer

Annie Wu (anniedotexe)

If you have any questions, comments, or concerns, feel free to contact me below.

Connect via Email

This project was created for educational purposes of learning development, documentation, and deployment and for personal and open-source use.

Default values of the project are used to run @ac_celeste_bot.

If you like my content or find this code useful, give it a or support me by buying me a coffee 😀

Buy Me A Coffee


Additional Information

Owner
anniedotexe
Web Dev · UI Design · Social Media Bots · Photography
anniedotexe
Gorrabot is a bot made to automate checks and processes in the development process.

Gorrabot is a Gitlab bot made to automate checks and processes in the Faraday development. Features Check that the CHANGELOG is modified By default, m

Faraday 7 Dec 14, 2022
🤖 A fully featured, easy to use Python wrapper for the Walmart Open API

Wapy Wapy is a fully featured Python wrapper for the Walmart Open API. Features Easy to use, object oriented interface to the Walmart Open API. (Produ

Carlos Roso 43 Oct 14, 2022
simple discord token grabber with webhook hiding feature.

Token Grabber A simple Discord token grabber with base64 webhook encoding, it uses pastebin as a database to get webhook, so next time u dont get your

0 Dec 01, 2021
A simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statistical tables and plots to users as Telegram messages.

telegram-stats-bot Telegram-stats-bot is a simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statist

22 Dec 26, 2022
This is a straightforward python implementation to specifically grab basic infos about IPO companies in China from Sina Stock website.

SinaStockBasicInfoCollect This is a straightforward python implementation to specifically grab basic infos about IPO companies in China from Sina Stoc

CrosSea 1 Dec 09, 2021
A fast and expressive Craigslist API wrapper

pycraigslist A fast and expressive Craigslist API wrapper. ⚠ As of September 2021, it is believed that Craigslist added a rate-limiter. It is advised

Ira Horecka 24 Dec 28, 2022
Authenticate your League of legends account on riot client in a few lines of code.

lol-authenticator v1.0.0 Content index Project Setup Dependencies Project Setup Dependencies Python v3.9.6 If you don't have Python installed on your

Cássio Fontoura 5 Aug 28, 2022
A Telegram Music Tag Editor Bot that can remove almost all usernames in the music tags and add own username instead.

Music Tag Editor Bot A Telegram Music Tag Editor Bot that can remove almost all usernames in the music tags and add own username instead. It can also

14 Oct 21, 2022
Public Mirror of Team 15's Code and Reports for RBE 3002 B21

RBE3002 Team 15 Lab Repository Team 15's Repository for all code written for RBE 3002 using the Robotis TurtleBot3 Written By Matthew Haahr, Leo Morri

Matthew Haahr 3 Mar 21, 2022
Discord Bot Personnal Server - Ha-Neul

Haneul Bot, it's a discord for help me on my personnal discord, she do a lot of boring and repetitive stain. You can use on your own server if you want, you just need to find a host for the programm

Maxvyr 1 Feb 03, 2022
Python 3 tools for interacting with Notion API

NotionDB Python 3 tools for interacting with Notion API: API client Relational database wrapper Installation pip install notiondb API client from noti

Viet Hoang 14 Nov 24, 2022
Telegram File Renamer Bot

RENAMER_BOT Telegram File Renamer Bot Configs TG_BOT_TOKEN - Get bot token from @BotFather API_ID - From my.telegram.org API_HASH - From my.telegram.o

Lntechnical 37 Dec 27, 2022
A discord bot that will help you browse/download nhentai sources.

Risa Introduction Risa is an nHentai discord bot that will help you browse and download your favorite doujin inside your own discord server. Hosting M

markee7 14 Oct 25, 2021
discord bot made in discord.py

udeline discord bot made in discord.py, which's main features include: general use server moderation fun commands other cool commands dependencies dis

1 Feb 08, 2022
Rhythm bot clone for discord written in Python and uses YouTube to get media files.

Tunebot About Rhythm bot clone for discord written in Python and uses YouTube to get media files. Usage You need a .env file within the same directory

1 Oct 21, 2021
Hcl.py is an Amino client for Python

Hcl.py Hcl.py Hcl.py is an Amino client for Python. It provides to access aminoapps Web, app and socket servers. Developed BY Kapidev And Upgraded BY

Oustex 3 Dec 02, 2021
Actively maintained, pure Python wrapper for the Twitter API. Supports both normal and streaming Twitter APIs.

Twython Twython is a Python library providing an easy way to access Twitter data. Supports Python 3. It's been battle tested by companies, educational

Ryan McGrath 1.9k Jan 02, 2023
Exchange indicators & Basic functions for Binance API.

binance-ema Exchange indicators & Basic functions for Binance API. This python library has been written to calculate SMA, EMA, MACD etc. functions wit

Emre MENTEŞE 24 Jan 06, 2023
📈 A Discord bot for displaying the download stats of a repository made with Python, the Hikari API and PostgreSQL.

📈 axyl-stats axyl-stats is a Discord bot made with Python (with the Hikari API wrapper) and PostgreSQL, used as a download counter for a GitHub repo.

Angelo-F 2 May 14, 2022
Plazmix API wrapper for Python

An optimised, easy to use Plazmix API wrapper written in Python

Someone 2 Nov 16, 2021