m3y54m / twitter-retweet-bot

A simple keyword-based retweeter bot for Twitter API V2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Retweeter Bot with Twitter API V2

This repository holds the source code of a bot that utilizes Twitter API V2. The bot will constantly search through the Twitter timeline for tweets containing your specified keywords, which can be edited in the track.json file.

Note: Due to recent changes in Twitter Developer accounts, Free plan is not able to search tweets or retweet them. You should have a Basic or Pro account to use this bot.

Prerequisites

First you should (or it is recommended to) install Poetry for package management:

pip install poetry

Install all the required packages based on poetry.lock using this command:

poetry install

To update all packages to their latest versions you can use this command:

poetry update

Run the bot

python src/main.py

Project Strcture

src/track.json

This bot simply uses keywords in this file to find desired tweets. This file consists of two parts:

  • include: All keywords, hashtags, and mentions that should exist in the tweets bot is looking for.
  • exclude: All keywords, hashtags, and mentions that should NOT exist in the tweets.

src/main.py

This is the entry point of the program. It Gets keywords from src/track.json and processes them and generates valid search rules for out Twitter bot. It also runs a Flask web server to monitor or control the bot's activity. Finally it runs the bot's main application.

src/bot.py

This file defines the application and behavior of this Twitter bot. It is using Twitter API v2 StreamingClient to monitor Twitter live steam of tweets based on the rules defined for it.

Currently the bot only likes and retweets the tweets that match the rules.

src/server.py

A Flask web server is run to monitor or control the bots activity.

src/get_access_token.py

This file is a independent utility to generate user-specific access tokens for the bot's Twitter API app and the bot's functionality is not related to this file.

Development Resources

About

A simple keyword-based retweeter bot for Twitter API V2

License:GNU General Public License v3.0


Languages

Language:Python 96.9%Language:Nix 3.1%