JSON output, Ping services

November 18, 2008

Migrating from one blogging platform to another can be a pain. I don't want it to be difficult to move away from this one so I've added JSON output. Any page that displays entries can be represented in machine readable JSON by adding ?format=json to the end of the URL.

def render_json(self, entries):
    json_entries = [{
        "title": entry.title,
        "slug": entry.slug,
        "body": entry.body,
        "author": entry.author.nickname(),
        "published": entry.published.isoformat(),
        "updated": entry.updated.isoformat(),
        "tags": entry.tags,
        "link": "http://" + self.request.host + "/e/" + entry.slug,
    } for entry in entries]
    json = {"entries": json_entries}
    self.response.headers["Content-Type"] = "text/javascript"
    self.response.out.write(simplejson.dumps(json))

For example the archives page contains every entry on the blog. So this link is all you need to migrate.

It'll also now ping Google when you publish a new entry. Eventually I'll support more pinging services.

code and json