Easy Peasy: Using the Flickr API in Python

Since I'm often required to hit the ground running at $MPOW on projects, I was a little concerned when I roped myself into assisting our photo archives with a Flickr project. The first goal was to get a subset of the photos uploaded, and quickly. Googling and poking around the Cheeseshop led me to Beej's FlickrAPI for Python. Little did I know that it would be dead simple to get this project going. To authenticate:

 
def create<em>session(api</em>key, api<em>secret):
    """Creates as session using FlickrAPI."""
    session = flickrapi.FlickrAPI(api</em>key, api<em>secret)
    (token, frob) = session.get</em>token<em>part</em>one(perms='write')
    if not token:
        raw<em>input("Hit return after authorizing this program with Flickr")
    session.get</em>token<em>part</em>two((token, frob))
    return session
 
That was less painful than the PPD test for tuberculosis. Oh, and uploading?
 
flickr.upload(filename=fn, title=title, description=desc, tags=tags, callback=status)
Using this little code plus a few other tidbits, I created an uploader that parses CSV files of image metadata exported from an Access database. And when done, the results look a little something like this.

2 comments ↓

#1 Jodi Schneider on 03.27.08 at 10:24 am

Beautiful, Mark! Any chance of enriching the tags?

For instance, I’d like to be able to find Kepler by Kepler or Johannes, rather than Kepler, Johannes.

#2 Mark Matienzo on 03.27.08 at 11:02 am

I’d like to add this functionality, but it wouldn’t be too easy to do automatically when you consider names like “Van de Graaff”. I guess I could do some regular expression magic – I’ll talk to my coworkers and see what they think.

Leave a Comment