Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Python Flickr Backup Script (Untested)

DZone's Guide to

Python Flickr Backup Script (Untested)

·
Free Resource

# 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)
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}