Created
September 25, 2009 17:05
-
-
Save blech/193683 to your computer and use it in GitHub Desktop.
Sort a Flickr gallery by date
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
#!/usr/bin/python | |
import flickrapi | |
import simplejson | |
keys = { | |
'flickr_key': " ", # put your key and secret here. I'm not giving you mine. | |
'flickr_sec': " ", | |
} | |
token = '' | |
# TODO fix token arguments / auth (probably needed to edit gallery) | |
flickr = flickrapi.FlickrAPI(keys['flickr_key'], keys['flickr_sec'], | |
token=token, store_token=False, cache=True) | |
flickr.cache = flickrapi.SimpleCache(timeout=300, max_entries=200) | |
# TODO use Gallery API to fetch photo ID and secret | |
# for now I look at the source and extract these | |
images = [ (1678716, '6f78156db4'), | |
(3823396, 'daa492bc5c'), | |
(47220662, 'b2e5f91c5e'), | |
(51248209, 'e08b3d51dd'), | |
(125198581, 'da5036f103'), | |
(131467192, '1c45714e6a'), | |
(149718161, '4ce2a66eda'), | |
(2350965079, '4511cb7e66'), | |
(2460581961, '5dc0582ef9'), | |
(2692575231, '7f1a5f820e'), | |
(3947092937, '2a7b41c78a'), | |
(3501484509, '6ee134e65b'), | |
(1241064467, '2a22470598'), | |
] | |
image_hash = {} | |
for id, secret in images: | |
rsp = flickr.photos_getinfo( format='json', | |
nojsoncallback="1", | |
photo_id=id, | |
secret=secret | |
) | |
info = simplejson.loads(rsp) | |
taken = info['photo']['dates']['taken'] | |
image_hash[id] = taken | |
# relies on dates sorting asciibetically | |
ordered = [(key, image_hash[key]) for key in image_hash.keys()] | |
ordered.sort() | |
for id, taken in sortedList: | |
print id, taken | |
# TODO use Gallery API to set order. For now, do it manually. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment