Skip to content

Instantly share code, notes, and snippets.

@earlwlkr
Created March 28, 2016 04:53
Show Gist options
  • Save earlwlkr/61dc19ebe460e9927d99 to your computer and use it in GitHub Desktop.
Save earlwlkr/61dc19ebe460e9927d99 to your computer and use it in GitHub Desktop.
import requests
import json
import os
import urllib.request
def download_file(url):
local_filename = url.split('/')[-1].split('?')[0]
print('Downloading file %s' % local_filename)
r = requests.get(url, stream=True)
with open('./Photos/' + local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
return local_filename
def getUserPhotos(username):
users_found = json.loads(requests.get('http://iconosquare.com/controller_nl.php?action=nlGetMethod&method=findUsername&value=%s&max_id=false' % username).content.decode("utf-8") )
user_id = users_found['data'][0]['id']
max_id = '0'
photo_id = 1
if not os.path.exists('./Photos'):
os.makedirs('./Photos')
while True:
try:
photos_response = json.loads(requests.get('http://iconosquare.com/controller_nl.php?action=getPhotoUserPublic&user_id=%s&max_id=%s' % (user_id, max_id)).content.decode("utf-8") )
for image_data in photos_response['data']:
download_file(image_data['images']['standard_resolution']['url'])
max_id = photos_response['pagination']['next_max_id']
except:
break
getUserPhotos('desireevent')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment