Skip to content

Instantly share code, notes, and snippets.

@loopymonkey
Forked from rubinovitz/instagram_mine.py
Last active August 29, 2015 14:05
Show Gist options
  • Save loopymonkey/84845a6f1a22de462e0c to your computer and use it in GitHub Desktop.
Save loopymonkey/84845a6f1a22de462e0c to your computer and use it in GitHub Desktop.
download instagram images from 3rd party api url
from datetime import datetime
import urllib2
import urllib
import json
import os
#wait for network
time.sleep(45)
def ajaxRequest(url=None):
"""
Makes an ajax get request.
url - endpoint(string)
"""
req = urllib2.Request(url)
f = urllib2.urlopen(req)
response = f.read()
f.close()
return response
# url to query for pictures
nextUrl = "YOUR URL"
print nextUrl
# while there is a next url to go to
# request the data at that endpoint
instagramJSON = ajaxRequest(nextUrl)
instagramDict = json.loads(instagramJSON)
instagramData = instagramDict[0]
# for every picture
for picDict in instagramDict:
# get the image url and current time
print picDict
image = picDict["images"]["standard_resolution"]
imageUrl = image["url"]
print image
time = str(datetime.now())
# download the photo and save it
urllib.urlretrieve(imageUrl, time+".jpg")
print "all done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment