Created
July 4, 2012 16:26
-
-
Save kghose/3048152 to your computer and use it in GitHub Desktop.
Short python script using flickrapi to grab favorites from your account
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
import flickrapi, urllib, os, argparse | |
parser = argparse.ArgumentParser(description='Grab favorites from a user') | |
parser.add_argument('-f', '--folder', help='Folder', default='./') | |
parser.add_argument('-n', '--number', help='Number', default=10) | |
parser.add_argument('-k', '--apikey', help='Api Key') | |
parser.add_argument('-s', '--apisecret', help='Api Secret') | |
parser.add_argument('-u', '--userid', help='User id') | |
args = parser.parse_args() | |
api_key = args.apikey | |
api_secret = args.api_secret | |
flickr = flickrapi.FlickrAPI(api_key,api_secret) | |
(token, frob) = flickr.get_token_part_one(perms='read') | |
flickr.get_token_part_two((token, frob)) | |
print 'Fetching ' , args.number , ' into ' , args.folder | |
folder = os.getcwd() + '/' + args.folder | |
photos = flickr.favorites_getList(user_id=args.userid, per_page=args.number, page=1) | |
counter = 0 | |
for photo in photos.find('photos').findall('photo'): | |
pa = photo.attrib | |
fname = "{0}/{1}.jpg".format(folder,pa['id']) | |
if not os.path.exists(fname): | |
sizes = flickr.photos_getSizes(photo_id=pa['id']).find('sizes').findall('size') | |
found = False | |
for sz_code in ['b', 'c', 'z']: | |
for size in sizes: | |
if sz_code == size.attrib['source'][-5]: | |
url = size.attrib['source'] | |
(filename, headers) = urllib.urlretrieve(url, fname) | |
counter += 1 | |
print counter, filename, size.attrib['label'] | |
found = True | |
break | |
if found: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment