This was originally a comment on reddit, but I figure it’d help other folks out, so I’m going to put it up here too.
So git, is a great tool for backing up your code projects, allowing you to easily save and manage different versions of your project among your friends and coworkers. But despite all the friendly packaging, on github, it was really intimidating. I didn’t know what a branch was, let alone a fetch, merge or anything even more complex like trunks and bisecting. Eventually though, I got the basics sorted out. It was enough to send (push) a few of my repositories over to github. This was my basic experience:
What’s up? Today we’re going to look at how to retrieve the stories (official term for submissions or selfposts) from any given subreddit. What we’re going to do is pretty simple, essentially just customizing a url with the proper subreddit and reading the JSON object returned. It’s going to be a pretty short one. I’m going to attach the login code I’ve written along with the code we’ve looked at today so that you can just copy and paste it into your IDE and start playing with it, right away. Just make sure you’ve got all the required module installed, mentioned here. Hit the jump to get started!
Tinypaste Link for entire code
Welcome to the first part of my reddit API tutorial for Python 2.7! In this short tutorial we will just focus on signing in to reddit’s API so we can interact with it later.
Hopefully you’ve read the introduction on the modules we’ll be using found here, so if you’re a beginner, you won’t be that lost.
Before we start, I am just going to give you a brief overview of what we are going to do: create a python DICT that has your reddit account name and password in it, so that we can send it to the API with our request. Then, armed with our modhash that we received from the API, we can move on to interacting with reddit, which we’ll check out in the next part of this tutorial!
Tinypaste of the entire code as seen at the bottom of the page
Hit the jump for how to login to the reddit’s API. As usual, the full code will be shown at the end of this page.