You are here

agent

Rolling feed on jpstacey.info

Following my recent success with putting a Flickr feed on my website’s front page is the conversion of this to an all-purpose feed reporter, where RSS/Atom flavour and feed specifics are dealt with by Javascript associative arrays of functions, keyed on both variables respectively.

If you’re lucky then the feed should wait a bit while it loads the XML via Javscript’s XMLHTTPResponse() code (querying proxies all on my website for foreign feeds like del.icio.us). Then it will report the first feed it finds, while still loading other feeds in the background. Every 15s or so it swaps to a new feed.

After writing it easily in Firefox, I found that a number of drastic changes were required for IE, as follows:

  1. IE doesn’t seem to have great support for the IMG element’s width or height properties, at least before the image is rendered on the page. For the Flickr feed, if imgElem.width == 0, I’ve had to employ some horrible regular expressions on imgElem.outerHTML (which isn’t supported by non-IE browsers, so it’s all a bit of a hack).
  2. IE doesn’t support assigning arbitrary properties to elements. I was using these to smuggle a collection of titles and descriptions (keyed by date) into a function and that of course failed. You can use setAttribute() for string-like properties, but not objects, which I’ve had to pass as parameters or in some reserved scopes.
  3. IE is very unforgiving about character encodings, behaviour which I haven’t been able to work around yet. Some of the programs that create my feeds (specifically Blosxom) aren’t very Unicode-wise and hence will happily produce invalid content. Firefox is very forgiving of this (which may or may not be the right XML way to do it, but is certainly a very patient way of dealing with web content generally). I’m currently working on my proxies to sort this out somehow, even if I have to filter everything down to the ASCII character set.

The Javascript is a single, monolithic file which relies on a beta-release version of Mochikit, and is available at http://www.jpstacey.info/index/javascript/index.js. Feel free to scrape it and re-use anything you find interesting there.

Blog category: 

Flickr images without the API

A number of posts are currently in stasis waiting for me to actually finish them, but I thought it was worth mentioning the selection of my most recent Flickr photos that now graces my homepage. While the rest of that page awaits serious styling and content work, I’ve dilly-dallied by creating this bit of eye-candy.

The loveliness of this slightly hackish system is that it uses AJAX (with help from MochiKit) to fetch an RSS 2.0 feed, so it doesn’t require an understanding of Flickr’s huge quasi-REST API. Also, because one can guarantee the RSS feed is good XML, the responseXML property of the XMLHTTPRequest object can be trusted. This means you don’t need to do any string-based munging of the returned data to transform it into the HTML seen on the page: there’s an XML DOM already set up for you. It also means that the method could be adapted to other RSS feeds, in principle.

The major difficulty was getting the Javascript to request a URL from a different server from the one that the current page was on (quick summary: you can’t, because of Javascript’s security rules). But it took two minutes, one and a half of which were googling, to set up a proxy of this feed in Perl using LWP::Agent.

There’s other minor problems to be overcome—the first paragraph of the RSS description feed is a rather trite “username posted a photo:” so naturally I got rid of that, and the images are actually shown half-size because it’s easier to change the <img /> tag’s width and height than it is to try and work out the dimensions and locations of the real thumbnails—but it works. And all in under an hour’s programming.

Blog category: 
Subscribe to RSS - agent