giulionf / realtweetornotbot

Scans screenshots of tweets on reddit and links the corresponding tweet
https://www.reddit.com/u/realtweetornotbot
MIT License
76 stars 5 forks source link

RealTweetOrNotBot

NOTE This repository is unfortunately retired as the Twitter API does not allow reading tweets in free tier anymore.

The Reddit Tweet Finder Bot

The bot is currently (13th of December 2019) ranked as the number one bot on Reddit by the unofficial Reddit bot Ranking!

RealTweetOrNotBot is a Reddit Bot, that analyzes image posts in given SubReddits and - if it detects a twitter screenshot - posts a link to it in the comments. It is written in Python3.

Setup

To function you need to install the required modules from the requirements.txt using:

pip install requirements.txt

Once that's done, you need to set certain environment variables to keep sensitive information out of the code.

Environment Variable Description
REDDIT_CLIENT_ID Reddit API Client ID
REDDIT_CLIENT_SECRET Reddit API Client Secret
REDDIT_USER_AGENT Reddit API User Agent
REDDIT_FETCH_COUNT Numeric Value representing how many posts are fetched with every cycle
REDDIT_SUMMON_COUNT Numeric value of username summons to be fetched every cycle
REDDIT_USERNAME Username of the Bot's Reddit account
REDDIT_PASSWORD Password of the Bot's Reddit account
REDDIT_POST_MAX_AGE_DAYS Numeric value of how old a fetched post can be at max
REDDIT_SUBREDDITS List of subreddits joined by a + symbol e.g. "me_irl+whitepeopletwitter+meirl+2meirl4meirl"
DATABASE_URL URL to your PostGres Database
DATABASE_USER User to log into the Database
DATABASE_PASSWORD Password to log into the Database
SEARCHTWEETS_BEARER_TOKEN Twitter API Bearer Token
SEARCHTWEETS_ENDPOINT Endpoint used for searching tweets on the Twitter API
WORKER_COUNT Amount of worker threads to process a request simultaneously
TWITTER_API_MAX_AGE_DAYS Max age of tweets to process - 7 is the limit for free tier of Twitter API
RUN_MODE 'release' or 'debug', depending on which way to run the bot.
RUN_INFINITELY 1 if run in infinite loop or 0 if only running one routine

Database Setup

To use the bot a database is needed. It can be a local database or a remote one specified in the Environment Variables of the Operating System. Use the following Queries to create the needed tables:

CREATE TABLE seen_posts (
    "id" SERIAL PRIMARY KEY,
    "post_id" VARCHAR (255),
    "found_tweet" VARCHAR (255)
);
CREATE TABLE summary (
    "id" SERIAL PRIMARY KEY,
    "time" timestamp DEFAULT CURRENT_TIMESTAMP,
    "posts_seen" integer,
    "tweets_found" integer,
    "last_post_id" integer
);

Running the Bot

The Bot is configured to be running on [Heroku] but can be run just as well on any Operating System supporting Python. To run the bot, use:

python src/main.py