Created
April 5, 2013 15:07
-
-
Save andrewjkerr/5320025 to your computer and use it in GitHub Desktop.
Generates ten pages of ten Instagram URLs that have a specific tag (in this case 'kitten'.)
---
Uses python2.7!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Created on Apr 4, 2013 | |
@author: andrewjkerr | |
Shout out to kiks for the sweet Python lesson last night! | |
''' | |
import urllib2 | |
import json | |
# Get dat response from dat API yo | |
# https://api.instagram.com/v1/tags/{tag-name}/media/recent | |
kittenURL = "https://api.instagram.com/v1/tags/kitten/media/recent?client_id={client_id}" | |
def printKitties(kittenURL): | |
kittenResponse = urllib2.urlopen(kittenURL) | |
# Convert to JSON | |
kittenJSON = json.loads(kittenResponse.read()) | |
kittenData = kittenJSON["data"] #list of instagram photos | |
for kitty in kittenData: | |
print(kitty["link"]) | |
kittenNextData = kittenJSON["pagination"] | |
kittenNextURL = kittenNextData["next_url"] | |
return kittenNextURL | |
numPages = 10 | |
count = 0 | |
nextURL = kittenURL | |
while count <= numPages: | |
print "New page: " + str(count) + "**" | |
nextURL = printKitties(nextURL) | |
count += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment