Tag Archives: 2.7

Reddit API Tutorial Part 2: Getting all the submissions to any given subreddit

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

Continue reading Reddit API Tutorial Part 2: Getting all the submissions to any given subreddit

reddit API Part 1: Logging In

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.

Continue reading reddit API Part 1: Logging In

Imgur API part 2: Downloading a Gallery

This is the second installment of my Imgur API: ‘How to entire download Imgur Galleries’. Check out part 1 here in case you missed how to log into the API and upload an image!

I’m actually sort of cheating here, because we don’t actually need to use the API at all here, if we don’t want to. That is because we’re only going to deal with the galleries that are built from the images submitted to reddit. This means after you’re done with this tutorial, you’ll be able to just set the script to a given subreddits name, and grab all the images that have been submitted to /r/aww or /r/wallpapers.

I will be writing another tutorial soon for galleries and albums unrelated to reddit.com as well as grabbing gallery information, such as the title and other descriptive things like that, but that’s less related to the actual downloading of the gallery, which is what we’re interested in today!

Please note that I’m working with Python 2.7 on Windows 7 64-bit, so you might have to modify the code slightly to accommodate for your platform, or OS.

Anyways, hit the jump to get started!

Edit: reddit user: easttntoppedtree caught that it maxes out at 56 images, so you’ll have to add /page/PAGENUMBERHERE.json to the end of the url to get the next 56 images like so: http://imgur.com/r/scarlettjohansson/top/page/1.json’ while keeping in mind that 0 (zero) is a valid page number

Tinypaste link for the full working code, as seen at the bottom of the page

Continue reading Imgur API part 2: Downloading a Gallery

Imgur API part 1: getting an Anonymous Key and uploading an image

This first part will focus on creating an anonymous API (Application programming interface) key for your script to use, and then upload an image to imgur.com.  For this, and any following tutorals, I will be using Windows 7×64, with Python 2.7.

You will need to create an anonymous API key at http://imgur.com/register/api_anon, it’s really simple, just feed the name of your app, so the dudes over at Imgur know what your intentions are, and then your personal information and finally, the reCaptcha, to verify you’re not a bot. The next page will give you your developer API key; this is important. This key will allow you to interact with the Imgur API. Since this is the limited Anonymous API, you will only have access to basic functions, like uploading images from your computer or from another website, and getting gallery and image information. Luckily, that’s enough for our purposes here.

The documentation for the Imgur API that we’ll be using today is found here: http://api.imgur.com/resources_anon, and the requests module documentation is here http://docs.python-requests.org/en/latest/user/quickstart/. Now, open up your favourite text editor for coding. I like using Wing IDE Professional,  but I’m sure notepad++ and any other one would work just as nicely.  This is where the fun part begins. Hit the jump!

Tinypaste of the full working code!

Continue reading Imgur API part 1: getting an Anonymous Key and uploading an image