Please note that this page is now outdated - for any updates to the London Underground, you should use my dedicated Tube Status API and RSS feeds
I've been spending some time making an RSS feed of the London Underground tube status as I've been working on a few projects that could use one. You would think that Transport for Londons nice web 2.0 style website would provide this basic requirement but alas they don't. There are a few developers out there who have written some scraping scripts to convert this information, but most of them no longer work as they haven't been updated to work with the new site.
Previously I have used the script at conor.net to power any projects requiring a tube RSS feed but this went down a few weeks ago when I was in the middle of some crucial testing. So, like any other crazy developer would, I decided to write my own PHP scraping script that would generate me a nice RSS feed to basically tell me TFL had messed up my journey home!
For those of you just looking for an RSS feed of the London Underground tube delays, you can find it at http://tubeupdates.com/rss/ - This is automatically updated every minute and will email me if anything goes wrong so I can fix it! If you are going to use it for any projects, please let me know so that I can monitor bandwidth, etc. If you are interested in how it works, then the code that powers this is below - feel free to use and modify it for your own projects:
As I mentioned earlier, I am working on a few projects that utilise this script and I shall be making those available shortly. However, for a sneak peek, you can check out Tube Updates, an API for any developer that would like to make use of this data. There are still a few improvements to be made but you get the general idea!
I've spent some time updating my firefox extensions so that all of them work with Firefox 3 Beta 3. At present they can only be downloaded from this site as it takes the Mozilla Addons team a few days to approve updates. My extensions page is now back up and running though and contains details on all 3 of my Firefox Extensions (Font Finder, Stop! Hammertime!, and STOP in the name of love) as well as download links for the new releases.
I won't be making any further updates to the stop buttons (apart from making them work with future version of Firefox) but I will be continuing development on Font Finder which could benefit from a visual overhaul as well as a clipboard function! I'll be updating on here when it happens so sign up to the RSS feed for the latest news!
I've been having a play around with Google Charts recently but came across a problem with the range of values that can be used. With simple encoding, you can only have values between 0 and 64, and with text encoding only values between 0 to 100. This is annoying when dealing with things such as tracking website hits or weight when values are typically much higher.
I played around with some functions to try and factorise the numbers so that they would be in the range of 0 to 100 but this didn't go so well so I decided to tackle Google's extended encoding.
This is a system of encoding that basically takes a pair of alphanumeric characters and translates them into a number between 0 and 4095 (much better!). So for example, B9 translates to 125 and .a would translate to 4058. However, although this has a much larger range, it's a bit harder to get your head around and so what is needed is a simple function (or two) to convert to and from the extended encoding. Predictably, I have said PHP functions here:
They work fairly simply by taking advantage of PHP's casting methods in that a string can be interpreted as an array.
In the first function, array_to_extended_encoding(), an array of numbers should be passed e.g. array(250,39,400,1904,2). The function first lists all of the extended encoding characters in order as one string named $characters. It then loops through our array of numbers, and creates two variables; $first and $second. In $first, we store the number from our array divided by 64 and rounded down using the floor() function. For $second, we use the modulus operator (%) to find the remainder once the number from the array is divided by 64. We then take both $first and $second and work out the encoding by looking up the numbers from within the $characters cast as an array. This gives us 2 characters which make up the extended encoding for the number. We keep extending the value of $encoding until we end up with a string representing the full extended encoding of the array passed to the function.
The second function, extended_encoding_to_array(), is slightly more advanced. It accepts a string as its only parameter which should be an extended encoding (e.g. $encoding = 'AA..B9aC'). We first list all of the characters in a string as we did for our previous function, but then we create two arrays which will contain all of the numbers we need to decode the extended encoding. In $first, we create an array of each character in the $characters string as a number multiplied by 64 (so the letter b would be 64 as it is signified by number 1 in the array multiplied by 64). Within $second we perform a similar operation but instead just assign the number of the character rather than multiplying it by 64. This gives us two arrays, with keys relating to each character that can be used as an encoding and values as the numerical equivalent. It is now a simple case of splitting the string that was passed to the function into chunks of 2 characters using str_split() and looping through the returned array setting the value of each character within the pair from the arrays we created. We then add the two returned numbers together to give us the decoded figure and add it to an array which will be returned by the function.
Simple? It has certainly made things a lot easier for the functions I'm writing for a PHP wrapper for Google Charts and hopefully it will help somebody else as well. If you have any questions or comments, please get in touch.
As some of you may have noticed, the new site design has caused the Firefox Extensions page to go awry. This will return shortly (along with a few new extensions) but for the time being you are better to go the Mozilla Addons site to download the extensions.