Skip to content

Instantly share code, notes, and snippets.

@earlwlkr
Created March 28, 2016 06:59
Show Gist options
  • Save earlwlkr/9931708cf27b3cf3f8ce to your computer and use it in GitHub Desktop.
Save earlwlkr/9931708cf27b3cf3f8ce to your computer and use it in GitHub Desktop.
import requests
import json
import os
folderName = 'Photos'
urlFindUser = 'http://iconosquare.com/controller_nl.php?action=nlGetMethod&method=findUsername&value={0}&max_id=false'
urlGetPhotos = 'http://iconosquare.com/controller_nl.php?action=getPhotoUserPublic&user_id={0}&max_id={1}'
def download_file(url):
local_filename = url.split('/')[-1].split('?')[0]
print('Downloading file {0}'.format(local_filename))
r = requests.get(url, stream=True)
with open('./{0}/{1}'.format(folderName, local_filename), 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
return local_filename
def get_user_photos(username):
print('-- Start processing for username {} --'.format(username))
users_found = json.loads(requests.get(urlFindUser.format(username)).content.decode("utf-8"))
try:
user_id = users_found['data'][0]['id']
print('Found matching user ID {0} for username {1}.'.format(user_id, username))
except:
print('No users found')
return
max_id = '0'
folderPath = './{}'.format(folderName)
if not os.path.exists(folderPath):
os.makedirs(folderPath)
while True:
try:
photos_response = json.loads(requests.get(urlGetPhotos.format(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
print('-- End processing for username {} --'.format(username))
get_user_photos('desireevent')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment