DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Python Flickr Backup Script (Untested)

10.12.2007
| 5307 views |
  • submit to reddit
        
# flickrbackup.py - Matt Croydon - http://postneo.com
import flickr # http://jamesclarke.info/projects/flickr/
import BitBucket # http://www.other10percent.com/?p=15
import urllib
me = flickr.people_findByUsername("postneo")
bucket = BitBucket.BitBucket("postneo-flickr")
page = 1
total_photos = found_photos = 0
while 1:
    try:
        photos = flickr.people_getPublicPhotos(me.id, 100, page)
        for photo in photos:
            total_photos = total_photos + 1
            if bucket.has_key("%s-%s" % (photo.title, photo.id)):
                pass # we already have this photo
            else:
                data = urllib.urlretrieve("http://static.flickr.com/%s/%s_%s_o.jpg" % (photo.server, photo.id, photo.secret), "flickr.jpg")
                bits = BitBucket.Bits(filename="flickr.jpg")
                bucket["%s-%s" % (photo.title, photo.id)] = bits
                print "saving %s" % photo.title
                found_photos = found_photos + 1
        page = page + 1
    except AttributeError:
        break # We probably got an empty bucket
print "Found %s photos, saved %s new photos" % (total_photos, found_photos)