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
Facebook fishing on telegram bot

Facebook-fishing Facebook fishing on telegram bot تثبيت الاداة pkg update -y pkg upgrade -y pkg install git -y pkg install python -y git clone https:/

sadamalsharabi 7 Oct 18, 2022
Matrix trivia bot with python

Matrix-trivia-bot Getting started See SETUP.md for how to setup and run the template project. Project structure A reference of each file included in t

1 Nov 16, 2021
Lol qq parser - A League of Legends parser for QQ data

lol_qq_parser A League of Legends parser for QQ data Sources This package relies

Tolki 3 Jul 13, 2022
Discord Bot for Genshin Impact Wish Simulating

Genshin Inpact Wish Simulation Discord Bot Bot Links Invite Reddit Official Discord Features Discord embed reaction menu for wishes Simple code scalin

Jeffrey Shum 2 Jan 04, 2023
Polars-fun - Example notebooks for how to use pola.rs

polars-fun Polars is an awesome Rust DataFrame library with Python language bindings. This repo makes it easy to run Polars code on your local machine

Matthew Powers 2 Jun 28, 2022
Petit webhook manager by moi (wassim)

Webhook Manager By wassim oubliez pas de ⭐ le projet Installations il te faut python sinon quand tu va lancer le start.bat sa va tout installer tout s

wassim 9 Jul 08, 2021
Paginator for Dis-Snek Python Discord API wrapper

snek-paginator Paginator for Dis-Snek Python Discord API wrapper Installation: pip install -U snek-paginator Basic Example: from dis_snek.client impo

1 Nov 04, 2021
Touca SDK for Python

Touca SDK For Python Touca helps you understand the true impact of your day to day code changes on the behavior and performance of your overall softwa

Touca 12 May 18, 2022
An Amazon Price Tracker app helps you to buy which product you want within sale price by sending an E-Mail.

Amazon Price Tracker An Amazon Price Tracker app helps you to buy which product you want within sale price by sending an E-Mail. Installing Download t

Aytaç Kaşoğlu 2 Feb 10, 2022
Automatically download any NFT collection from OpenSea.

OpenSea NFT Stealer The sole purpose of this script is to download any NFT collection from OpenSea. How does it work? Basically, the OpenSea website a

Dan 111 Dec 29, 2022
Find people to play tennis with.

40Love 40Love is a full-stack web application that helps tennis players find hits at public tennis courts. Players can select public courts on the map

Tanner Schmutte 27 Jun 08, 2022
Manage Proxmox KVM Virtual Machines via Slack bot.

proxmox-slack-bot Create KVM Virtual Machines on Proxmox, the easy way. Not much works works here yet... Setup dev environment Setup fully editable st

Plenus Pyramis 3 Mar 20, 2022
A chatbot on Telegram using technologies of cloud computing.

Chatbot This project is about a chatbot on Telegram to study the cloud computing. You can refer to the project of chatbot-deploy which is conveinent f

Jeffery 4 Apr 24, 2022
🐲 Powerfull Discord Token Stealer made in python

🐲 Follow me here 🐲 Discord | YouTube | Github ☕ Usage 💻 Downloading git clone https://github.com/KanekiWeb/Powerfull-Token-Stealer

Kaneki 61 Dec 19, 2022
:globe_with_meridians: A Python wrapper for the Geocodio geolocation service API

Py-Geocodio Python wrapper for Geocodio geocoding API. Full documentation on Read the Docs. If you are upgrading from a version prior to 0.2.0 please

Ben Lopatin 84 Aug 02, 2022
RP2 is a privacy-focused, free, open-source US cryptocurrency tax calculator

Privacy-focused, free, open-source cryptocurrency US tax calculator, up to date for 2021: it handles multiple coins/exchanges and computes long/short-term capital gains, cost bases, in/out lot relati

eprbell 123 Jan 04, 2023
A suite of utilities for AWS Lambda Functions that makes tracing with AWS X-Ray, structured logging and creating custom metrics asynchronously easier

A suite of utilities for AWS Lambda Functions that makes tracing with AWS X-Ray, structured logging and creating custom metrics asynchronously easier

Amazon Web Services - Labs 1.9k Jan 07, 2023
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
Projeto do segundo módulo da Resilia

@ Projeto Resilia : Módulo 2 Vamos jogar Forca ! O jogo da forca é um jogo em que o jogador tem que acertar qual é a palavra proposta, tendo como dica

Mateus Sartorio 2 Feb 24, 2022
Migrate BiliBili watched anime to Bangumi

说明 之前为了将B站看过的动画迁移到bangumi写的, 本来只是自己用, 但公开可能对其他人会有帮助. 仓库最近无法维护, 程序有很多缺点, 欢迎 PR 和 Contributors 使用说明 Python版本要求:Python 3.8+ 使用前安装依赖包: pip install -r requ

51 Sep 08, 2022