-
-
Save loopymonkey/84845a6f1a22de462e0c to your computer and use it in GitHub Desktop.
download instagram images from 3rd party api url
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
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