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
A VCVideoPlayer Bot for Telegram made with 💞 By @TeamDeeCoDe

VC Video Player How To Host ✨ Heroku Deploy ✨ The easiest way to deploy this Bot is via Heroku. Credit 🔥 |🇮🇳 Louis |🇮🇳 Sammy |🇮🇳 Blaze |🇮🇳 S

TeamDeeCode 6 Feb 28, 2022
Auto Liker, Auto Reaction, Auto Comment, Auto Follower Tool. RajeLiker Credit Hacker.

Auto Liker, Auto Reaction, Auto Comment, Auto Follower Tool. RajeLiker Credit Hacker. Unlimited RajeLiker Credit Hack. Thanks To RajeLiker.

Md. Mehedi Hasan 32 Dec 28, 2022
Moderation and Utility Discord bot.

Qrista An advanced Moderation and Utility Discord bot. Features Uses Hikari and Lightbulb as a command handler Advance Logging & Whole new enviroment

Blaze Camp 2 Jan 11, 2022
ETL for tononkira.serasera.org

python-tononkiramalagasy-api Api Endpoints: ### get artists - /artists/int:page [page_offset = 20] ### get artist's songs, index was given by

Titosy Manankasina 1 Dec 24, 2021
可基于【腾讯云函数】/【GitHub Actions】/【Docker】的每日签到脚本(支持多账号使用)签到列表: |爱奇艺|全民K歌|腾讯视频|有道云笔记|网易云音乐|一加手机社区官方论坛|百度贴吧|Bilibili|V2EX|咔叽网单|什么值得买|AcFun|天翼云盘|WPS|吾爱破解|芒果TV|联通营业厅|Fa米家|小米运动|百度搜索资源平台|每日天气预报|每日一句|哔咔漫画|和彩云|智友邦|微博|CSDN|王者营地|

每日签到集合 基于【腾讯云函数】/【GitHub Actions】/【Docker】的每日签到脚本 支持多账号使用 特别声明: 本仓库发布的脚本及其中涉及的任何解锁和解密分析脚本,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。

87 Nov 12, 2022
Baota-docker - Deploying baota panel via docker

baota-docker Deploying baota panel via docker. 通过docker一键部署宝塔面板。 一、前言 好像很多人对这个感兴

Mr. Cat 15 Dec 12, 2022
An attempt to make a bot that can auto-archive Danganronpa KG RPs on Discord.

Danganronpa Killing Game Archiving Bot An attempt to make a bot that can auto-archive Danganronpa KG RPs on Discord. The final format is meant to look

Astrea 1 Nov 30, 2021
SpaceManJax's open-source Discord Bot. Now on Github!

SpaceManBot This is SpaceManJax's open-source Discord.py Bot. Now on Github! This bot runs on Repl.it, which is a free online code editor. It can do a

Jack 1 Nov 16, 2021
A Python bot that uses the Reddit API to send users inspiring messages.

AnonBot By Edric Antoine A Python bot that uses the Reddit API to send users inspiring messages. When a message includes 'What would Anon do?', the bo

1 Jan 05, 2022
Program that uses Python to monitor grade updates in the Genesis Platform

Genesis-Grade-Monitor Program that uses Python to monitor grade updates in the Genesis Platform Guide: Install by either cloning the repo or downloadi

Steven Gatanas 1 Feb 12, 2022
A discord bot made by the community (uses python)

discord community bot context: this is a discord bot made by the community by community i mean people adding commands to the bot or changing the bot b

TR ASH 0 Oct 11, 2022
A youtube videos or channels tag finder python module

A youtube videos or channels tag finder python module

Fayas Noushad 4 Dec 03, 2021
Tools to download and aggregate feeds of vaccination clinic location information in the United States.

vaccine-feed-ingest Pipeline for ingesting nationwide feeds of vaccine facilities. Contributing How to Configure your environment (instructions on the

Call the Shots 26 Aug 05, 2022
SquireBot is a Discord bot designed to run and manage tournaments entirely within a Discord.

Overview SquireBot is a Discord bot designed to run and manage tournaments entirely within a Discord. The current intended usecase is Magic: the Gathe

7 Nov 29, 2022
A discord bot for tracking Iranian Minecraft servers and showing the statistics of them

A discord bot for tracking Iranian Minecraft servers and showing the statistics of them

MCTracker 20 Dec 30, 2022
Discord bot do sprawdzania ceny pizzy.

Discord bot do sprawdzania ceny pizzy w pizzeri Bombola. Umieszczony jest na platformie Heroku, dzięki czemu działa 24/7. Commands List Info: Jako com

1 Sep 18, 2021
Este programa tem como objetivo o cadastro dos usuários. Assim, caso a autenticação seja feita, permitir que o usuário entre em determinado sistema ou programa.

LoginPy Este programa tem como objetivo o cadastro dos usuários. Assim, caso a autenticação seja feita, permitir que o usuário entre em determinado si

Jonas Carvalho 4 Dec 23, 2021
A simple notebook to stream torrent files directly to Google Drive using Google Colab.

Colab-Torrent-to-Drive Originally by FKLC, this is a simple notebook to stream torrent files directly to Google Drive using Google Colab. You can eith

1 Jan 11, 2022
TeslaPy - A Python implementation based on unofficial documentation of the client side interface to the Tesla Motors Owner API

TeslaPy - A Python implementation based on unofficial documentation of the client side interface to the Tesla Motors Owner API, which provides functiona

Tim Dorssers 233 Dec 30, 2022
An example of using discordpy 2.0.0a to create a bot that supports slash commands

DpySlashBotExample An example of using discordpy 2.0.0a to create a bot that supports slash commands. This is not a fully complete bot, just an exampl

7 Oct 17, 2022