Skip to content

Instantly share code, notes, and snippets.

@ofZach
Forked from yunjey/download_flickr_image.py
Last active June 28, 2020 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ofZach/3daf605fbbdf8ebccf7dac454e77e762 to your computer and use it in GitHub Desktop.
Save ofZach/3daf605fbbdf8ebccf7dac454e77e762 to your computer and use it in GitHub Desktop.
downloading images from flickr using python-flickr
# First, you should install flickrapi
# pip install flickrapi
import flickrapi
import urllib
from PIL import Image
from urlparse import urlparse
# Flickr api access key
flickr=flickrapi.FlickrAPI('c6a2c45591d4973ff525042472446ca2', '202ffe6f387ce29b', cache=True)
keyword = 'sunset'
photos = flickr.walk(text=keyword,
tag_mode='all',
tags=keyword,
extras='url_c',
per_page=200, # maybe you can try different numbers..
sort='relevance')
urls = []
for i, photo in enumerate(photos):
#print (i)
url = photo.get('url_c')
urls.append(url)
if i > 200:
break
#print (urls)
for url in urls:
if url is not None:
urlparse(url)
#print url
#print urlparse(url).path.split('/')[-1]
urllib.urlretrieve(url, urlparse(url).path.split('/')[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment