Archive for October, 2005

Apple’s recent announcements disappointing

Admittedly, I was really hoping for a video version of AirTunes. At the moment I’m stuck with way too many wires snaking around my living room to get from my laptop to my surround sound system.

In a similar vein, my other gripe is with video play back in iTunes 6. Even with an Airport Express selected for sound, video plays the sound through the laptop speakers. If I’d wanted it to play through the laptop speakers, I would have asked for it. Yes, there is a delay for wireless music, but I would have hoped they were close to fixing that by now.

As for the iTunes Store announcements, they just add a growing resentment, as due to the Australian music labels, we are out in the cold down here.

My sister recently asked me how to download music. I’d assumed she meant by peer to peer, but no, she wanted to know how to buy online. We have a couple of online options for music purchase in Australia, but none that start with iTunes.

Back to waiting …

On the bright side, I’m stoked with my iPod nano :)

Exporting Delicious Library to the web

I’ve been using Delicious Library for a while now and have been incredibly happy with the results. I even managed to figure out which books I had on loan and more importantly discovered I was missing some books from my collection!

The other thing I’d been playing with was including some books on this site that I like. You may have noticed them down the side. There is a bit of PHP code behind the pictures, but I still need to add in the Amazon id number for each book.

My aim is to use Delicious Library to keep track of my physical media, including rating it, and to publish the highest rated media onto the site. Given that Library is basically a thick client built on top of Amazon, I could even include my referrer link, so if anyone buys anything I get a small commission to feed my book buying habits.

Library supports exporting its catalog as a tab separated file. I had hoped for an ‘Export to XML’ option, so it would be simple XSL transform and tada!

Given the Python focus of this site, it didn’t take long before I had a workable script up and running.

The important bits of the script are included below:


from Kid import *
import sys

def normalizeString(str):
    return str.replace('//', '/').replace('/ ', '<br/>').replace('*','<br/>*')

file = open(sys.argv[1], 'rb')
for line in file:
    lines.append(line[:-1])

headings = lines[0].split('t')

books = [dict(zip(headings, normalizeString(line).split('t'))) for line in lines[1:]]

Template(file='template.kid', books=books).serialize()

The Template object is from the Kid template library, which is responsible for generating the resultant XHTML. The template.kid file that I used iterates through the list of dictionaries of books and displays as links the ones that I’ve given a rating of (5/5).


<?xml version='1.0' encoding='utf-8'?>
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:py='http://purl.org/kid/ns#'>
  <head><title>Delicious Library</title></head>
  <body>
    <ul>
      <li py:for='book in books' py:if="book['rating'] == '5'">
        <a py:attrs="href='http://www.amazon.com/exec/obidos/ASIN/' + book['asin'] + '/pseudofish-20?creative=327641&camp=14573&link_code=as1'">
        ${book['title']}
        </a>
      </li>
    </ul>
  </body>
</html>

The end result, is that I can now add books into Library as I purchase and read them, and if I rate the book highly enough then it will turn up on this blog.

Source code and samples are available here. Requires Delicious Library (full or demo) and Kid.

Can a Python eat an Alligator?

The answer is maybe. Fox news has an interesting story about pythons in the Everglades.

It turns out that the question is less than rhetorical and that a python attempted to consume an alligator. Unfortunately for the python, it exploded in the process.

My favourite quote goes to:

“Clearly, if they can kill an alligator they can kill other species,” Mazzotti said. “There had been some hope that alligators can control Burmese pythons. … This indicates to me it’s going to be an even draw. Sometimes alligators are going to win and sometimes the python will win.

It is starting to remind me of a recent film with the tagline:

Whoever wins… We lose.

Comment spam hits a new level

An interesting read by Tom Coates about an advertising firm (maybe) using comment spam to promote cleaning products.

Linked via Hugh

I’ve been seeing more and more random comment spam on this blog, which Wordpress filters for me, but it still requires moderation. Fortunately, none has gotten through (so far) with vigilance taking up more time. Now even the legitimate looking comments seem to require checking.

Luckily, Cocoa development in Python is a fairly niche audience. I’m sure some of the bigger blogs are having even bigger issues with spam, which will be why comments get disabled on a lot of them.

I’m almost in agreement with Seth Godin that if you want to have the conversation, start your own blog and then link back to the article. Almost.

Update: And now an apology after the fact.

Pimp My Code, Part 5: In Python

Wil Shipley continues his Pimp My Code series with an article reviewing what should have been a very simple method to return a path inside the Application Support folder.

Well worth a read, both for the stylistic as well as the comedic commentary.

From my perspective, it is also a useful source of learning about Cocoa from one of the better programmers.

In Python, the final example looks something like:


from Foundation import *

def applicationSupportFolder():
    return NSSearchPathForDirectoriesInDomains(
        NSApplicationSupportDirectory, NSUserDomainMask, True
    )[0].stringByAppendingPathComponent_(
        NSProcessInfo.processInfo().processName())

Note: The code has been reformatted to (attempt to) fit your screen.