Source

Ochs / lib / flickr.py

Full commit
import simplejson
import flickrapi

from django.conf import settings

class Flickr(object):
    def __init__(self, instance):
        self.instance = instance

    def __getattr__(self, name):
        if getattr(self, name):
            pass
        a = getattr(self.instance, name)
        if not callable(a):
            return a
        def f(*args, **kwargs):
            if kwargs.get("format", "json") != "json":
                return a(*args, **kwargs)
            kwargs.update(format="json", nojsoncallback=1)
            resp = simplejson.loads(a(*args, **kwargs))
            if resp['stat'] != 'ok':
                raise flickrapi.exceptions.FlickrError(u"Error: %(code)s: %(message)s" % resp)
            return resp 

        if name == 'walk':
            return self.walk
        else:
            return f

flickr = Flickr(flickrapi.FlickrAPI(settings.FLICKR_API_KEY))