sm-photo-tool 1.13 released
23 04 2008Tonight I released version 1.13 of sm-photo-tool. Download it here:
http://sourceforge.net/project/showfiles.php?group_id=179298
Categories : python, sm-photo-tool
Tonight I released version 1.13 of sm-photo-tool. Download it here:
http://sourceforge.net/project/showfiles.php?group_id=179298
I released a new version of sm-photo-tool. It’s a simple script that that was originally written by John Ruttenberg wrote. I took it and packaged it in rpm form and have been maintaining it under source control (versus a forum).
sm-photo-tool help
Usage: sm-photo-tool create gallery_name [options] [file...]
sm-photo-tool create_upload gallery_name [options] [file...]
sm-photo-tool update [options]
sm-photo-tool full_update [options]
sm-photo-tool upload gallery_id [options] file…
sm-photo-tool –help for complete documentaton
It’s create to upload an entire directory of photos to smugmug from the command line.
I installed drupal on sourceforge this weekend. My old Welcome page for sm-photo-tool sucked, and I wanted something much more powerful than hand coded html files.
Based on my earlier “announcement”, zmugfs svn repo created: http://sm-photo-tool.svn.sourceforge.net/viewvc/sm-photo-tool/trunk/zmugfs/
I’ve been using smugmug.com to host my photos for almost 3 years now. I’ve been using sm-photo-tool to upload my pictures and I installed Fedora 7 for my wife to use to upload her pictures as well. I gave F-spot a try but I’m not a big fan. Uploading to smugmug using f-spot isn’t that easy either (well for more than a few photos).
So I had the idea “why can’t I open up a nautilus window and copy the photos to a new directory?” That’s when I remembered about FUSE but they don’t have a fs built for smugmug that I could find. So thatt’s my new project to create a FUSE based FS that connects to smugmug.com.
Hopefully, I don’t get bored and lose focus which is often the case with my ideas ![]()
I’ve been trying to figure out why my image upload to smugmug using HTTP PUT wasn’t working for quite some time. I always got a “connection closed” error. After looking at this example more closely I finally realized what my problem was. I forgot the freakin slash. The upload url is supposed to be http://upload.smugmug.com/filename. My code looked like this:
conn = httplib.HTTPConnection("upload.smugmug.com", 80)
conn.connect()
conn.request(”PUT”, filename, data, headers)
This obviously generates the following url: http://upload.smugmug.comXXX where XXX is the value of filename. That’s just outright wrong. SIGH! But I fixed it and now my uploads work. Here’s the working snippet:
conn = httplib.HTTPConnection("upload.smugmug.com", 80)
conn.connect()
conn.request(”PUT”, ‘/’ + filename, data, headers)
Now I can get back to finishing my XMLRPC to JSON migration of sm-photo-tool.
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">
<method>smugmug.images.getInfo</method>
<Info>
<Image id="134646762">
<Album id="2559293" />
<FileName>IMG_0112.JPG</FileName>
<Caption />
<Keywords />
<Position>1</Position>
<Date>2007-03-08 17:48:25</Date>
<Format>JPG</Format>
<Serial>0</Serial>
<Watermark>0</Watermark>
<Size>2553371</Size>
<Width>2592</Width>
<Height>1944</Height>
<MD5Sum>a7d81edf9fb659da1947514dbbcfb204</MD5Sum>
<LastUpdated>2007-03-08 17:48:34</LastUpdated>
<OriginalURL>http://familiarodriguez.smugmug.com/photos/134646762-O.jpg</OriginalURL>
<LargeURL>http://familiarodriguez.smugmug.com/photos/134646762-L.jpg</LargeURL>
<MediumURL>http://familiarodriguez.smugmug.com/photos/134646762-M.jpg</MediumURL>
<SmallURL>http://familiarodriguez.smugmug.com/photos/134646762-S.jpg</SmallURL>
<TinyURL>http://familiarodriguez.smugmug.com/photos/134646762-Ti.jpg</TinyURL>
<ThumbURL>http://familiarodriguez.smugmug.com/photos/134646762-Th.jpg</ThumbURL>
<AlbumURL>http://familiarodriguez.smugmug.com/gallery/2559293/1/134646762</AlbumURL>
</Image>
</Info>
</rsp>
This is the class I want to create:
class Image:
def __init__(self):
self.data = {}
def __setitem__(self, key, value):
#print "__setitem__(%s:%s)" % (key,value)
self.data[key.lower()] = value
def __getitem__(self, key):
#print “__getitem__(%s)” % (key)
return self.data[key.lower()]
def __str__(self):
return str(self.data)
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.
As you may know I’m working on updating sm-photo-tool from XMLPRC to REST. I wanted similar functionality with the REST implementation as with XMLRPC. That is I wanted to be able to do things like this:
sm = Smugmug()
sm.login.withPassword(”foo@foo.com”, “password”)
I couldn’t find a REST library I liked probably because it’s trivial as all you need is a properly formatted url. I knew it was possible to do the above with XMLRPC in python:
sm = ServerProxy("url")
sm.login.withPassword(…)
I looked through the xmlrpclib.py and stole the _Method implementation from it (with a slight modification):
class _Method:
# some magic to bind an XML-RPC method to an RPC server.
# supports “nested” methods (e.g. examples.getStateName)
def __init__(self, send, name):
self.__send = send
self.__name = name
def __getattr__(self, name):
return _Method(self.__send, “%s.%s” % (self.__name, name))
def __call__(self, **args):
print “__name: %s” % self.__name
print “args: ” + str(args)
return self.__send(self.__name, args)
Now I can make calls to Smugmug’s REST api.
sm = Smugmug()
sm.smugmug.login.withPassword(EmailAddress=”foo@foo.com”, Password=”foo”)
Next stop is to get the parsing of the XML response.
It’s been quite sometime since I’ve worked on sm-photo-tool so long that sourceforge changed the access url to svn.
On November 31, 2006 the access method for Subversion changed. This document reflects those changes. The old method had numerous problems, including spurious 50x error messages and other issues that kept it from functioning fully. This newly documented access method solves many, if not all of the issues with the old mechanism.
Users of the old method (https://svn.sourceforge.net/svnroot/PROJECTNAME) should switch to the new access method (https://PROJECTNAME.svn.sourceforge.net/svnroot/PROJECTNAME) using these steps:
I trashed my repo by using the old url and trying to rely on svn plugin in eclipse. Use the command line Luke. At work I use the command line, but for some reason I feel compelled to see if I can make better use of Eclipse. ARGH!
Sinc I make almost daily use of sm-photo-tool to upload my pictures to my smugmug gallery, I’ve decided to give it some much needed love. Get your minds out of the gutter, I’m talking about enhancing the software.
smugmug.com is recommending folks use REST, JSON, or serialized PHP to access their services. While XML-RPC is still available, it isn’t not recommended. sm-photo-tool uses XML-RPC at the moment and I think I’m going to switch it over to using REST instead.
TODOS