Git Product home page Git Product logo

phc-bot's Introduction

u/phc-bot

ARCHIVED

The repo has been archived, because Heroku killed its free tier, which this bot was running on.

Build and test codecov

Source code for the— ahem bot. You know the one.

The core of the bot is in the app.py file. main.py is just a Flask endpoint for Heroku, which is where the bot is currently hosted.

Summoning

Just summon the bot by its name (u/phc-bot) on whichever subreddit you please. You don't have to summon it on the PHC subreddit – it's always checking the posts there – but feel free to do so anyway.

Setup

Requirements

Other than the usual package requirements (pip install -r requirements.txt), you need to install tesseract-ocr. On Ubuntu or other Debian-based distros, you can install it with sudo apt install tesseract-ocr tesseract-ocr-eng.

I can't remember, but I think you'd also need to install Python source files (sudo apt install python3-dev), so if you see #include <Python.h> in an error log somewhere, try that.

Environment variables

First you need to set up environment variables. You can use the .env file for this. See .env.sample for all possible environment variables. The ones that start with REDDIT_ are mandatory.

See the guide on obtaining client secret and client ID here.

If you want to use a custom database other than Sqlite (e.g. Postgres on Heroku), set DATABASE_URL as well.

Database

Just run the following command, and you should be good to go.

./create_schema.py

Running the bot

Note: Please don't run the bot yourself, unless u/phc-bot is dead for good. There isn't much point in two instances of the bot running at the same time.

The bot operates in two different modes: submissions and mentions. Each mode can be invoked as ./app.py {mode}.

In submissions mode, it processes all the posts from the designated subreddit. In mentions mode, it processes each "mention", or call to summon (i.e. /u/phcbot) made by users.

main.py, which is what runs on Heroku, runs in the two modes concurrently using threads.

Docker

You can also run this image with docker. The included Dockerfile is meant for production (runs Flask server via gunicorn), but you can easily mount the source directory as a volume and use it for development as well.

Start by building the image:

docker build --tag phc-bot .

Before you can start using the container, you need to create the schema in whatever database you're using (either SQLite or an external one, configure this using .env file).

docker run --name phc-bot --env-file .env -p 8000:8000 -d phc-bot
docker exec phc-bot python create_schema.py

For development:

docker run --name phc-bot -d -v "$(pwd):/app" --env-file .env -p 8000:8000 phc-bot --reload
docker exec phc-bot python create_schema.py

This will run mount the current folder to the container's /app folder, and run gunicorn with the --reload flag, so any time you make changes to your host directory, gunicorn will reload itself.

Contributing

This is a pretty dumb bot at this point, so feel free to improve it!

phc-bot's People

Contributors

dependabot[bot] avatar repulsivesheep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.