Idea sharing

Simon Willison and I are clearly birds of a feather. He spied my idea of having my blogroll show last updated times, which I got after he pointed me at, and implemented it himself. This is the way the web should work. Of course, I’ve now had to go one better… Actually, I was working on this before I ever saw Simon’s post, so it’s not just pathetic one-upmanship. :) Anyway, the blogroll on the left now remembers when you last visited one of its links, and if that blog has been updated since the last time you clicked that link, it will say (new!). So you don’t even need to remember whether you’ve seen the latest post or not. The big caveat here, clearly, is that there’s no way my poor little bit of code can know whether you’ve visited that site without clicking the link, by getting there some other way. Clearly there are two possible solutions here: either make the browser start page for the whole world, or live with it being inaccurate sometimes. Well, I know which one I’m going for. In our “Ask Dr. Code” interlude, a brief description of how it’s done: it’s not too hard. The links in the blogroll have onclick attributes that call the Javascript visitBlog function. That does a little bit of jiggery-pokery with cookies to store the current time (i.e., the time when you clicked the link) and the link you clicked in a cookie (the jiggery-pokery is to make sure that it doesn’t overwrite settings for other URLs you’ve clicked from the blogroll, and does overwrite any previous settings for this URL). The code which displays the blogroll (as seen in the previous post) now reads the cookie server-side and checks whether the cookie time is older than the update time from, and writes (new!) if it is. See? Nothing to it. Changed server-side Castalian code below — the “visitBlog” stuff is all the new bit.

import xml.dom.minidom,urllib,rfc822,time

# The favourites file is fetched from once per hour by cron
fp = urllib.urlopen("")
dom = xml.dom.minidom.parseString(
upd = dom.documentElement.getAttribute('updated')
updtup = rfc822.parsedate(upd)
updtime = time.mktime(updtup)
updtime = updtime + (5*60*60)   # correct for being behind

visitBlog = request.cookies("visitBlog")
visitedTimes = {}
if visitBlog:
    for item in visitBlog.split("|"):
        i = item.split("=")
        if len(i) == 2:
            visitedTimes[i[0]] = i[1]

for n in dom.documentElement.childNodes:
    if n.nodeType == n.ELEMENT_NODE:
        if n.tagName == 'weblog':
            nam = n.getAttribute('name')
            chgtme = updtime - int(n.getAttribute('when'))
            tme = time.strftime('%d/%m %I.%M %p',time.gmtime(chgtme))
            url = n.getAttribute('url')
            updatedText = "(last updated %s)" % tme
            if visitBlog:
                if visitedTimes.has_key(url):
                    if float(visitedTimes[url]) < chgtme:
                        updatedText = updatedText + " (new!)"
            response.write('<a onclick="visitBlog(this.href)" href="%s">%s</a> <span style="font-size:75%%">%s</span>' % (url,nam,updatedText))

We (meaning “the weblogging community”) need to be doing loads more stuff like this, I think; making things simple and automatic. This is why kryogenix is now running on MT rather than xlog, my custom blogging CMS — although xlog manages the core functionality (posts, comments) fine, it’s all the little stuff (pings to, RSS) that is making blogging really good, and I get all that for free with MT. ——-

I'm currently available for hire, to help you plan, architect, and build new systems, and for technical writing and articles. You can take a look at some projects I've worked on and some of my writing. If you'd like to talk about your upcoming project, do get in touch.

More in the discussion (powered by webmentions)

  • (no mentions, yet.)