Slack Reddit



This is my first time using Praw so when I was reading up on how to use it I came across Build a reddit bot that was pretty much what I wanted. So I used most of their code for the Reddit side of things.

You can find the source for this on Github: Reddit Slack Bot

I recently became the moderator of the Learn Ruby on Rails subreddit. I want to build out the subreddit and add relevant information on setting up a dev environment, Ruby and Rails tutorials, and foster a community of learning.

To that end I created a free slack team for the subreddit so teachers and learners could come together. Invite yourself to our Slack team!

Reddit

(I wrote this script in Python and yes, I get the irony of using Python for a Ruby based subreddit.) :)

Contribute to vmilojevic/slack-reddit-notifier development by creating an account on GitHub. Slack wants to support people in the world who are doing good things. That’s why we offer special discount pricing for qualified nonprofit organizations and educational institutions. Slack for nonprofits. Slack for education. Get more information on billing at Slack.

I thought it would be a good idea to have posts made to the subreddit show up in the Slack channel. I’ve seen the equivalent for subreddits that have IRC channels and I didn’t think it would be very hard to accomplish. And it really wasn’t. Less than 50 lines of code!

There’s two libraries we’re going to need to install via pip.

We’re also going to need the os library but that’s a core part of Python, so nothing to install there.

After we’ve installed those via pip we can start our script.

Import them into our script Microsoft office for mac 2011 standard sp3.

Connect to slack

For this we’ll need a token. You can create an API token for your team in your Slack settings.

Create user agent for Reddit api

Reddit requires you to give the name of a user agent to connect with. It can pretty much be anything (I think) so I gave mine a fairly descriptive name.

Create connection to reddit

Slack Vs Ms Team

Storing id’s of submissions in a text file for now.

That should probably eventually be stored in a database, probably sqlite.

First check to see if the file exists, if it doesn’t create an empty array to store the submission ids

Slack Reddit Emoji

If the file does exist then read it in, split on the new line characters and filter out None as it’s possible to have a blank file.

Praw call to connect to our subreddit of choice!

Loop through the new submissions. We’re only grabbing 5 each time

Open our text file and write out the new submission.id so we don’t post it again.

Miscellaneous

Reddit also asks that you only hit their api once every 30 seconds. To monitor the new submissions I set a cron job to run this every minute. Video copilot optical flares for mac. I tested this by letting the newest 5 submissions get posted to slack, then I created a test post to make sure it was posted. Autocad 2013 lt for mac. When it showed up in our Slack channel I knew we were set!