Sometimes it makes more sense to just stop flogging the darn code.
I had been working on a moblog script for a while, with somewhat disastrous results (if you’ve been seeing wierd orphan posts titled “this is fierce cat” you’ve been stumbling on the detritus of my experiments). The more I poked at it the less it wanted to work and the more I realized that in attempting to learn the movable type API, XML-RPC, procmail and MIME all at once I had kind of gotten in over my head. And then it didn’t help that my script was a structural mess so when I attempted to make changes the whole thing fell apart. Hey Laura: there are these things called local variables. Maybe you’ve heard of them.
So: give up, take some time away, and then approach the problem from a new angle. Forget the MIME and the email part for now. I was having trouble with my script because procmail didn’t want to write files to the blog directory with the right permissions. Apparently I can’t do that and the right way to add image or other media files to a blog is to upload them via moveable type and XML-RPC. So I focussed on a script to do that and only that. I figured that a general-purpose media upload script might come in handy for things other than moblogs (I’m thinking of setting up applescripts on my mac so that when I drop an image from my camera into an upload folder it’ll automatically upload it to the blog for later posting…now won’t THAT be cool.)
My other error in the first script was arrogantly trying to do everything myself. I learn best by reading API documentation and then trying stuff myself in my own code. Just using other people’s code feels like a cheat to me and I don’t learn stuff if I copy and paste. (I suppose this is one reason why I’m really good at writing API documentation: I know what a programmer needs from API docs because I use them really deeply myself. but I digress.)
This time, however, I admit I took shortcuts. And what do you know. This time it works.
I have a couple more things to add to it but in a bit I’ll post the code and write up a big thingie about how to use it.