Skip to content

Instantly share code, notes, and snippets.

@nguyenlamlll
Created June 21, 2019 14:30
Show Gist options
  • Save nguyenlamlll/014b07f1600f1ea8fd42eacb6e22a047 to your computer and use it in GitHub Desktop.
Save nguyenlamlll/014b07f1600f1ea8fd42eacb6e22a047 to your computer and use it in GitHub Desktop.
FlickR Image Downloader
# Tested with Python 3.
# Install the dependencies first.
# pip install flickrapi
# pip install pillow
import flickrapi
import urllib.request
from PIL import Image
import os
# Flickr api access key
flickr=flickrapi.FlickrAPI('YOUR_FLICKR_KEY_HERE', 'YOUR_SECRET_HERE', cache=True)
# Change this keyword accordingly to your search desires
keyword = 'dandelion'
print("Initialize and finiding images...")
print("Finding keyword is: " + keyword)
photos = flickr.walk(text=keyword,
tag_mode='all',
tags=keyword,
extras='url_c',
per_page=2000,
sort='relevance')
urls = []
for i, photo in enumerate(photos):
url = photo.get('url_c')
urls.append(url)
# Limit image count to download
if i > 2000:
break
print("Found " + str(len(urls)) + " images")
# Create directory to store images
os.makedirs('downloaded-images', exist_ok=True)
# Download image from the URLs
for i, url in enumerate(urls):
if (urls[i] is None):
continue
print('Downloading: ' + str(urls[i]) + '...')
urllib.request.urlretrieve(urls[i], 'downloaded-images/' + keyword + '-' + str(i) + '.jpg')
print("--------------------------------------------")
print("Download DONE.")
print("--------------------------------------------")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment