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
Python wrapper for Wikipedia

Wikipedia API Wikipedia-API is easy to use Python wrapper for Wikipedias' API. It supports extracting texts, sections, links, categories, translations

Martin Majlis 369 Dec 30, 2022
Protection-UB - Simple Group Protection userbot running on python3 with ARQ

Protection-UB Simple Group Protection userbot running on python3 with ARQ ⚠️ Not

szsupunma 1 Feb 06, 2022
Name says it all/Instructions are in README file.

Discord-Webhook-Spammer Name says it all/Instructions are in README file. Setup 1. pip install discord-webhook ( In console, terminal or whatever you

Catto 1 Mar 21, 2022
This is simply code for bitcoin fair value.

About The Project This is a code for bitcoin fair value, its simply exclude bubble data using RANSAC method, and then plot the results. Check youtube

BitcoinRaven 4 Mar 26, 2022
AWS DeepRacer Free Student Workshop: Run faster by using your custom waypoints

AWS DeepRacer Free Student Workshop: Run faster by using your custom waypoints Reward Function Template for waypoints def reward_function(params):

Yuen Cheuk Lam 88 Nov 27, 2022
This Is Advanced Version Of Old Radio Player, An Telegram Bot to Play Radio/Music in Channel or Group Voice Chats.

Telegram Radio Player V2 An Telegram Bot to Play Radio/Music in Channel or Group Voice Chats. This is also the source code of the bot which is being u

SAF ONE 81 Dec 03, 2022
Trading bot rienforcement with python

Trading_bot_rienforcement System: Ubuntu 16.04 GPU (GeForce GTX 1080 Ti) Instructions: In order to run the code: Make sure to clone the stable baselin

1 Oct 22, 2021
Step by Step Guide To Install Discord Py Master Branch on Replit

Guide to Install Discord Py Master Branch on Replit Step 1 Create an empty repl on replit Step 2 Add this Basic Code to the file main.py so as to chec

Pranav Saxena 7 Nov 18, 2022
Autov2new - Pro Auto Filter Bot V2

Pro Auto Filter Bot V2 Deploy You can deploy this bot anywhere. Watch Deploying

1 Jan 06, 2022
Mark Sullivan 66 Dec 13, 2022
Polar devices Python API and CLI.

loophole - Polar devices API About Python API for Polar devices. Command line interface included. Tested with: A360 Loop M400 Installation pip install

[roscoe] 145 Sep 14, 2022
Buy early bsc gems with custom gas fee, slippage, amount. Auto approve token after buy

Buy early bsc gems with custom gas fee, slippage, amount. Auto approve token after buy. Sell buyed token with custom gas fee, slippage, amount. And more.

Jesus Crypto 206 May 01, 2022
Unofficial calendar integration with Gradescope

Gradescope-Calendar This script scrapes your Gradescope account for courses and assignment details. Assignment details currently can be transferred to

6 May 06, 2022
A decentralized messaging daemon built on top of the Kademlia routing protocol.

parakeet-message A decentralized messaging daemon built on top of the Kademlia routing protocol. Now that you are done laughing... pictures what is it

Jonathan Abbott 3 Apr 23, 2022
Open Source API and interchange format for editorial timeline information.

OpenTimelineIO is currently in Public Beta. That means that it may be missing some essential features and there are large changes planned. During this phase we actively encourage you to provide feedb

Pixar Animation Studios 1.2k Jan 01, 2023
This project, search all entities related to A2P in twilio

Mirror A2P Twilio This project, search all entities related to A2P in twilio (phone numbers, messaging services, campaign, A2P brand information and P

Iván Cárdenas 2 Nov 03, 2022
I-Spy is a discord and twitter bot 🤖 that keeps a check on usage foul language, hate-speech and NSFW contents

I-Spy is a discord and twitter bot 🤖 that keeps a check on usage foul language, hate-speech and NSFW contents. It is the one stop solution to monitor your discord servers and twitter handles against

Tia Saxena 5 Nov 16, 2022
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
google-resumable-media Apache-2google-resumable-media (🥉28 · ⭐ 27) - Utilities for Google Media Downloads and Resumable.. Apache-2

google-resumable-media Utilities for Google Media Downloads and Resumable Uploads See the docs for examples and usage. Experimental asyncio Support Wh

Google APIs 36 Nov 22, 2022
Python SDK for the Buycoins API.

This library provides easy access to the Buycoins API using the Python programming language. It provides all the feature of the API so that you don't need to interact with the API directly. This libr

Musa Rasheed 48 May 04, 2022