Trying to get a Reddit Bot up and running

I browse Reddit a lot and I thought it would be good programming practice to try and automate some of the more frequent tasks I do, namely searching for “Kobe Bryant” in the r/nba subreddit.

My first instinct was to write a bot from scratch, but writing a bot really isn’t my goal. My goal is to get a bot to do my searching for me. Writing an entire bot from scratch to accomplish one task seems like a case of “reinventing the wheel”, especially when there are tried-and-tested bots that exist.

I did some searching and found a stable bot framework called Snoo that is written in Ruby. It’s not as feature-rich as PRAW, which is written in Python, but it does the job and the code is easy to understand.

I can login fine. I can get my account settings fine. The problem comes when I try to add functionality. The problem isn’t with the bot itself, but with trying to interface with Reddit’s API.

My first task was to add a method to subscribe to a forum.

def subscribe(subreddit)
	logged_in?'',body:{uh: @modhash, action:'sub', sr: subreddit, api_type: 'json'})

Instead of success I get this response back

pry(main)> reddit.subscribe('/r/nba')
=> {"json"=>{"errors"=>[["USER_REQUIRED", "please login to do that", nil]]}}

It was suggested that I try passing my session cookie or my user name and I’ve tried those and no success…YET. So until then I’ll keep on pushing…

Leave a Reply