SkillAgentSearch skills...

Reddit Bot

🤖 Making a Reddit Bot using Python, Heroku and Heroku Postgres.

Install / Use

npx skills add race2infinity/Reddit-Bot

Installs into whichever agent you are using.

README

🤖 Making a Reddit Bot using Python and Heroku

This repo teaches you how to:

  • Make a Reddit Bot using the PRAW (The Python Reddit API Wrapper) Python package
  • Deploy your Reddit Bot on Heroku - A platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud
  • Install & use Heroku Postgres

Tweet

In this repo, I have made a Wordbook Bot which gives the meaning of particular word / phrase in the English / Slang language.


📝 Index

🎈 Why was Wordbook Bot made? <a name="why_was_wordbook_bot_made"></a>

Wordbook Bot was made to help Redditors:

  • Quickly look up the meaning of an English / Slang word you see
  • Find the right meaning of an English / Slang word
  • Find examples of the use of a word in natural language

⚙️ Installation <a name="installation"></a>

Running Locally <a name="running_locally"></a>

Clone or Download the repository

$ git clone https://github.com/kylelobo/Reddit-Bot.git
$ cd Reddit-Bot/Wordbook_Bot

Install Dependencies

$ sudo apt-get install python3.6
$ sudo apt-get install pip3
$ pip3 install praw --user
$ pip3 install requests --user

Setting up Environment Variables

An app’s environment-specific configuration should be stored in environment variables (not in the app’s source code). This lets you modify each environment’s configuration in isolation, and prevents secure credentials from being stored in version control.

💡 Note: Do not enter spaces before and after the "=" sign. Enter your values without the quotes (" ").

To set variable only for current shell:

VARNAME="your value"

To set it for current shell and all processes started from current shell:

export VARNAME="your value"      # shorter, less portable version

To set it permanently for all future bash sessions add such line to your .bashrc file in your $HOME directory.

To set it permanently, and system wide (all users, all processes) add set variable in /etc/environment:

sudo -H gedit /etc/environment

This file only accepts variable assignments like:

VARNAME="your value"

💡 Note: Do not use the export keyword here.

Here is the list of environment variables you need to set:

# Your Reddit ID & Pass
reddit_username="your_reddit_username"
reddit_password="your_reddit_password"

# Reddit API ID & Key (which you can get from here: https://www.reddit.com/prefs/apps/)
client_id="your_client_id"
client_secret="your_client_secret"

# Oxford Dictionary application ID & Key (which you can get from here: https://developer.oxforddictionaries.com/)
app_id="your_app_id"
app_key="your_app_key"

💡 Note: You need to logout from current user and login again so environment variables changes take place

You can check if your environment variables have been set by typing echo $var_name in terminal:

$ echo $reddit_username
Wordbook_Bot

Start the Bot

$ python3 wordbook_bot.py

Your bot should now be running.

🚀 Deploying the Bot on Heroku (Platform that allows you to host your bot) <a name="deploying_the_bot_on_heroku"></a>

  1. Firstly, make an account on Heroku.
  2. Make another directory and put all your python code in that, and make an empty file called __init__.py in it. 3. In your main directory, create two files: requirements.txt and runtime.txt.
  3. The requirements.txt file should contain output of the command pip freeze > requirements.txt. If you're not using virtualenv, you'll have delete all the lines with packages your code doesn't use.
  4. Runtime.txt just specifies which python version for Heroku to use. Mine just has the line "python-3.6.7" in it.

Now it's time to set up your git repo to use it as a remote.

Installing Git <a name="installing_git"></a>

$ sudo apt-get install git-all

Installing Heroku CLI <a name="installing_heroku_cli"></a>

$ sudo snap install --classic heroku

Verifying your installation

$ heroku --version
heroku/7.18.3 linux-x64 node-v10.12.0

Getting Started <a name="getting_started"></a>

$ heroku login
Enter your Heroku credentials.
Email: kyle@example.com
Password (typing will be hidden):
Authentication successful.

Initializing a local git repository <a name="initializing_a_local_git_repository"></a>

# Change your directory to your base directory
$ cd myapp
$ git init
Initialized empty Git repository in .git/
$ git add .
$ git commit -m "My first commit"
Created initial commit 5df2d09: My first commit
44 files changed, 8393 insertions(+), 0 deletions(-)
create mode 100644 README
create mode 100644 Procfile
create mode 100644 app/controllers/source_file
  ...

Your app’s code is now tracked in a local Git repository. It has not yet been pushed to any remote servers.

Creating a Remote Heroku <a name="creating_a_remote_heroku"></a>

For a new Heroku App

The heroku create CLI command creates a new empty application on Heroku, along with an associated empty Git repository. If you run this command from your app’s root directory, the empty Heroku Git repository is automatically set as a remote for your local repository.

$ heroku create
Creating app... done, ⬢ thawing-inlet-61413
https://thawing-inlet-61413.herokuapp.com/ | https://git.heroku.com/thawing-inlet-61413.git

You can use the git remote command to confirm that a remote named heroku has been set for your app:

$ git remote -v
heroku  https://git.heroku.com/thawing-inlet-61413.git (fetch)
heroku  https://git.heroku.com/thawing-inlet-61413.git (push)

For an existing Heroku App

If you have already created your Heroku app, you can easily add a remote to your local repository with the heroku git:remote command. All you need is your Heroku app’s name:

$ heroku git:remote -a thawing-inlet-61413
set git remote heroku to https://git.heroku.com/thawing-inlet-61413.git

Changing your App name on Heroku <a name="changing_your_app_name_on_heroku"></a>

You can rename an app at any time with the heroku apps:rename command. For example, to rename an app named “oldname” to “newname”, run the heroku apps:rename command from your app’s Git repository:

$ heroku apps:rename newname
Renaming oldname to newname... done
http://newname.herokuapp.com/ | git@herokuapp.com:newname.git
Git remote heroku updated

You can also rename an app from outside of its associated Git repository by including the --app option in the command:

$ heroku apps:rename newname --app oldname
http://newname.herokuapp.com/ | git@herokuapp.com:newname.git

💡 Note: When you rename an app, it immediately becomes available at the new corresponding herokuapp.com subdomain (newname.herokuapp.com) and unavailable at the old one (oldname.herokuapp.com).

If you use the Heroku CLI to rename an app from inside it's associated Git repository, your local Heroku remote is updated automatically. However, other instances of the repository must update the remote’s details manually.

You can run the following commands to update the remote’s details in other repository instances:

$ git remote rm heroku
$ heroku git:remote -a newname

Replace newname with the new name of the app, as specified in the rename command.

Deploying code <a name="deploying_code"></a>

To deploy your app to Heroku, you typically use the git push command to push the code from your local repository’s master branch to your heroku remote, like so:

$ git push heroku master
Initializing repository, done.
updating 'refs/heads/master'
  ...

Code diffs, manual and auto deploys via GitHub are also possible. To use GitHub as a deployment method:

Heroku Dashboard > Select your App > Deploy > Deployment Method > Connect to GitHub > App connected to GitHub > Select your GitHub repo

Thereafter, you can deploy code from your GitHub repo. If you have a local Git repo (if you have cloned your main GitHub repo), you will have to push your code to GitHub by using:

$ git push origin master

Deploying from a branch besides master

If you want to deploy code to Heroku from a non-master branch of your local repository (for example, testbranch), use the following syntax to ensure it is pushed to the remote’s master branch:

$ git push heroku 

Related Skills

View on GitHub
GitHub Stars124
CategoryOperations
Updated1mo ago
Forks14

Languages

Python

Security Score

100/100

Audited on Jun 22, 2026

No findings