tonights hackfest

My work on getting sm-photo-tool to use smugmug’s REST API continues. It’s been slow going as I’m also learning python as I go.

Tonight I can get image and album info using the REST API which returns me an XML document. I parse the document using DOM, and dynamically create a class with an internal map (or dict in python) of attributes.

Here’s a sample response from the getImageInfo REST API call:

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
   <Image id="134646762">
    <Album id="2559293" />
    <Caption />
    <Keywords />
    <Date>2007-03-08 17:48:25</Date>
    <LastUpdated>2007-03-08 17:48:34</LastUpdated>

This is the class I want to create:

class Image:
    def __init__(self): = {}
    def __setitem__(self, key, value):
        #print "__setitem__(%s:%s)" % (key,value)[key.lower()] = value
    def __getitem__(self, key):
        #print "__getitem__(%s)" % (key)
    def __str__(self):
        return str(

This makes it easy to use the resulting object.

    print "getimageinfo ---------------------------------------"
    imgInfo = sm1.getImageInfo(sessionid, images[0])
    print "imageinfo: " + str(imgInfo)
    print "TinyURL = " + imgInfo['TinyURL']
    print "imageid = " + imgInfo['imageid']
    print "albumId = " + imgInfo['albumId']

All of the code can be found here..

A more OO way is to have getter and setter methods, but I really like the ability to treat an object as a map and send it “messages”. I despise getters and setters now.

Off to bed now.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s