Day: March 22, 2006

  • Backing Up Flickr Photos with Amazon S3

    I love that I now have an Amazon S3 billing page that reads like a really cheap phone or water bill. I think that they’re silently changing the game (again) without telling anyone else. I really like the implications of this magepiebrain post and decided to start using S3 “for real” myself last night.

    The first ingredient was James Clarke’s flickr.py. Getting a list of my photos is pretty simple:

    import flickr
    me = flickr.people_findByUsername("postneo")
    photos = flickr.people_getPublicPhotos(me.id)

    The second ingredient for getting the job done was a pythonic wrapper around the Amazon example python libraries by Mitch Garnaat called BitBucket. Because it builds on the example libraries, there’s very little error checking, so be careful. Check out Mitch’s site for some example BitBucket usage, it’s pretty slick.

    Once I was familiar with both libraries, I put together a little script that finds all of my photos and uploads the original quality image to S3, using the flickr photo ID as the key. Here’s the complete code for flickrbackup.py, all 25 lines of it.

    After uploading 160 or so photos to Amazon, I owe them about a penny.

    Getting photos back out is really easy too:

    >>> import BitBucket
    >>> bucket = BitBucket.BitBucket("postneo-flickr")
    >>> bucket.keys()
    >>> bits = bucket[u'116201243']
    >>> bits.to_file("photo.jpg")