blog archive contact about feed

Rob's Blog - July 2004

Contents

Here are Rob's Blog entries for July 2004.

Blog entries for other months can be found in the main blog index.

Supporting Moblogging From The Nokia 7610

I've had to make some changes to my homebrew MMS moblog software now I have a Nokia 7610 phone.

The 7610 has a megapixel camera in it, which is far better than the very low res on in my old Nokia 7250.

The downside is I can't use the images it creates directly in my blog as they are far to high resolution. What I needed to do was to reduce the size of the image coming in before posting it to the blog. I achieved this using the Image::Magick Perl module.

This snippet of code takes an image from a filename, resizes it to a maximum of 450 wide and 350 high, and saves it back out with the original filename.

my $oldimage = new Image::Magick; $oldimage->Read($full_filename); $oldimage->Scale(geometry=>'450x350>'); $oldimage->Write(filename=>$full_filename);

The key to code is the use of geometry. Here I am saying what I would like the maximum boundries to be. Image::Magick does the rest, keeping the aspect ratio of the original image. The > at the end tells Image::Magick only to scale if the image is larger than that ratio, meaning smaller images are left untouched.

Great, so I have lovely scaled images. The next problem was that the software wasn't picking up the attachment.

The Nokia 7250 attaches the image directly with the MIME type of image/jpeg, however the Nokia 7610 attaches it with the MIME type of application/octet stream. This means it's hard to detect what the attachment is, however we are provided with a clue. We are given the recommended filename of the attachment, so scanning to see if it ends in .jpg lets us know if we have a JPEG image or not.

The code I use to detect the attachment in the octet-stream and put it into the variable $attachmentlooks something like this...

if ($entity->mime_type =~ m/application\/octet-stream/i) { if (($head->recommended_filename =~ /\.jpg$/i) || ($head->mime_attr("content-type.name") =~ /\.jpg/i)) { my $bh = $entity->bodyhandle; my $attachment = $bh->as_string;

Where $entity is a MIME::Entity object and $head is a MIME::Head object from the entity.

I now have a tool that can take MMS email messages from various phones and post remotely to my blog.

Entered: 2004-07-31 09:27:13
Modified: 2004-08-02 13:03:48
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=396

Where Is Everyone?

The office is empty, but it gives me a chance to test my new Nokia 7610.

MMS Blog image - /robblog/mmsimages/1091260742_1.jpg

PERMALINK - Where Is Everyone?
Mobile Blog Entry - Posted from an MMS enabled camera phone
Entered: 2004-07-31 08:59:03
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=395

Same Voice On Orange And Electrostar Trains?

Does the woman with the patronising voice who provides Orange's automatic answering and phone menu also providing the announcements on the new Southern Electrostar trains? It certainly sounded like it when I caught one from Brighton to London earlier today.

Entered: 2004-07-22 15:28:07
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=393

Comparing Email Addresses In JavaScript

I needed to write a quick JavaScript that could check if two email addresses were the same or not today. As it's so simple, I thought I'd share it.

Firstly we put the following JavaScript into a script tag.

function compareEmails(myForm) { if (myForm.email.value != myForm.email2.value) { alert("Your email addresses don't match. Please double check"); return false; } else { return true; } }

It takes a form, and compares the values of the fields called email and email2. If they are the same it returns true which lets the form submit normally.

However, if email and email2 are different it brings up an alert box telling our submitter the values are different, and returns false. Returning false means the script won't submit to the script specified in the action parameter so the user has to confirm their email address again.

The following HTML code gives an example of the scripts use.

<form action="dosomething.pl" onSubmit="compareEmails(this);"> Email :<input type="text" name="email" /> <br /> Verify Email: <input type="text" name="email2" /> <br /> <input type="submit" /> </form>

Of course the code can be used to compare any fields and not just email addresses. All you need to do is to change the field names in the JavaScript.

Enjoy!

Entered: 2004-07-20 12:26:54
Modified: 2004-07-26 12:44:04
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=392

Jellyatrics

First there were Jelly Babies, now there are Jellyatrics.

These sweets are now available in the shop at the Royal Sussex Hospital in Brighton.

I'm not sure if it's an insult or compliment to be given a bag.

MMS Blog image - /robblog/mmsimages/1090303640_1.jpg

PERMALINK - Jellyatrics
Mobile Blog Entry - Posted from an MMS enabled camera phone
Entered: 2004-07-20 07:07:20
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=391

Escorts On The NHS In Brighton

It would appear that cancer suffers at the Royal Sussex Hospital in Brighton get some unusual perks.

Patients and their escorts get a special dedicated parking area.

I wonder if escorts are now available on the NHS or if you have to go private to get one.

MMS Blog image - /robblog/mmsimages/1089933073_1.jpg

Mobile Blog Entry - Posted from an MMS enabled camera phone
Entered: 2004-07-16 00:11:13
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=390

That Google Job Ad

After reading the Google blog entry, Warning We Break For Number Theory I decided to give it a try.

Fortunately or unfortunately I read Davorg's use.perl journal entry on the Google job ad, so the first part was solved for me.

The second part needed a bit more thought. In the end it turned out to be primary school level maths, and a Perl script to generate a sequence of potential passwords. Once I had the potential passwords it was easy, and the first one worked.

Looking on the web afterwards I see that others had solved the puzzle and posted solutions online, so I won't give the answer here, but leave you to do your own research.

Enjoy!

PERMALINK - That Google Job Ad
Entered: 2004-07-15 09:54:55
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=389

UK Flight Arrival And Departure RSS Feeds

After the interest in my train arrival and departure RSS feeds, I decided to look at converting my WAP Heathrow Arrivals script to produce an RSS feed.

Instead of just rehashing the old code, I decided to write it again from scratch. The BAA now has a flight search script that makes it easier to look flights at all their UK airports. I decided to make use of this when building my new feed.

The Perl script can be found below if you want to install it on your own server to save my bandwidth, and a demo version is also available online at http://www.robertprice.co.uk/cgi-bin/flights_rss.pl.

The script takes 3 parameters.

  • flightnumber - the number of the flight you are interested in.
  • airport - the code of the airport you are interested in.
  • type - the type of data, either departures or arrivals.

For example, flight AA134 arriving at Heathrow would be http://www.robertprice.co.uk/cgi-bin/flights_rss.pl?flightnumber=AA134&airport=LHR&type=arrivals.

You'll notice how we have to use the standard 3 character IATA airport codes for the airport name. The script understands the following codes...

  • ABZ - Aberdeen
  • EDI - Edinburgh
  • LGW - Gatwick
  • GLA - Glasgow
  • LHR - Heathrow
  • SOU - Southampton
  • STN - Stanstead

Here is a screen shot of flight AA134 as shown on NetNewsWire Lite running on OS X.

RSS feed of flight AA134

The feed doesn't contain any syndication refresh information in it. I'm assuming it's best to just refresh by hand each time you want fresh data. Of course, adding the code would be trivial, so see my article on train departure and arrival RSS feeds for example code.

The script is fragile as it relies on screen scraping, but it works as of the 15th July 2004.

#!/usr/bin/perl -w ## Script to convert flight arrival and departures from BAA ## into RSS feeds. ## Takes the parameters "flightnumber","type" and "airport" ## Airports are LHR (Heathrow), LGW (Gatwick), STN (Stanstead), ## SOU (Southampton), ABZ (Aberdeen), GLA (Glasgow) or ## EDI (Edinburgh) ## Type is either "arrivals" or "departures" ## ## Robert Price - www.robertprice.co.uk - 13 July 2004 use strict; use CGI; use HTTP::Request; use LWP::UserAgent; use XML::RSS; ## Take the flightnumber, type, and airport my $CGI = new CGI; my $flightnumber = $CGI->param('flightnumber') || 'BY212B'; my $airport = $CGI->param('airport') || 'LHR'; my $type = $CGI->param('type') || 'arrivals'; ## The URL we have to screen scrape for the information. my $url = 'http://www.baa.com/cgi-bin/flightSearch.cgi?Airport=' . $airport . '&SearchType=' . $type . '&FlightNum=' . $flightnumber; ## Create our new browser, and pretend to be IE. my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); ## Get the data from the BAA website. my $req = HTTP::Request->new(GET => $url); $req->header('Accept' => 'text/html'); my $res = $ua->request($req); if ($res->is_success) { my $page = $res->content; ## Create our RSS data, update every 10 minutes. my $rss = new XML::RSS (version => '1.0'); $rss->channel( title => $flightnumber . ' ' . $type, link => 'http://www.baa.com/', description => 'The ' . $type . ' status of flight ' . $flightnumber, ); ## make sure there are no errors on the page and we have info. unless (($page =~ m[<td>No matching flights found</td></tr>]sg) || ($page =~ m[</SCRIPT>\s+</HTML>]sg) || ($page =~ m[unable to supply information]sg)) { ## regex out the information we need. $page =~ m[<td colspan=5><b>(.*?)</b></td></tr><tr id='n\d'>.*?<tr id='.*?' ><td width=12pcx>\&nbsp;</td><td><b>(.*?)</b></td><td>(.*?)</td><td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td></tr>]sg; ## Build a hash to store the information in. my $flight = { 'link' => $url, 'day' => $1, 'time' => $2, 'number' => $3, 'to_from' => $4, 'status' => $5, 'terminal' => $6, }; ## Add the flight to the RSS feed. $rss->add_item( title => $flight->{'time'} . ' - ' . $flight->{'number'} . ' (' . $flight->{'status'} . ')', link => $flight->{'link'}, description => "Day: " . $flight->{'day'} . ",\n" . "Time: " . $flight->{'time'} . ",\n" . "Number: " . $flight->{'number'} . ",\n" . "To/From: " . $flight->{'to_from'} . ",\n" . "Status: " . $flight->{'status'} . ",\n" . "Terminal: " . $flight->{'terminal'} . ",\n" . "Airport: " . $airport . ",\n" . "Arrivals/Depatures: " . $type. ",\n" ); ## We seem to have a problem, so return an error feed item. } else { $rss->add_item( title => $flightnumber . ' not found', link => 'http://www.baa.com/', description => 'Unable to find information for that flight. Please check your details or look on the BAA.com website' ); } ## Return the RSS feed, ensuring we have the correct MIME type. print "Content-type: application/rdf+xml\n\n"; print $rss->as_string; }

I'd welcome any feedback on this, so feel free to contact me.

Entered: 2004-07-15 09:08:14
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=388

Train Departure And Arrival RSS Feeds

I've been taking a greater interest in RSS feeds lately, and have installed a few feed readers.

One thing I've found that doesn't seem to exist is the ability to track train departure times via my feed reader. I thought this would be a great as I could see at a glance if my train was going to be late or not. With this is mind I visited NationalRail.co.uk's live departure board website and wrote a quick screen scraper to provide such a feed.

The script can be found a http://www.robertprice.co.uk/cgi-bin/train_departure_rss.pl, and takes a single parameter of stationcode with the station's code in it. The codes for national stations can be found on NationalRail.co.uk's live departure board website. For example, Hampden Park's code is HMD, as found at http://www.livedepartureboards.co.uk/ldb/summary.aspx?T=HMD. So, if we want to check this station's departures via the RSS feed we have to use the URL http://www.robertprice.co.uk/cgi-bin/train_departure_rss.pl?stationcode=HMD.

Here's an example of using NetNewsWire Lite on OS X.

Example of RSS feed in NetNewsWire Lite

Use of this script may break NationalRail.co.uk's acceptable use policy which prevents scripts from drawing large amounts of data from the site, so use it at your own risk, and please don't spoil this excellent service for us all. I believe it is OK to run this script occassionally for personal use, so to minimise impact the RSS feed is set to refresh every 10 minutes, where as the website refreshes every 2 minutes.

Users of mobile devices may like to check out NationalRail.co.uk's WAP service as they have a version of the departure boards for mobile phones.

The Perl script is included below so you can install it on your own server if needed, and also save my personal bandwidth. :-)

Please note that the code below has been superceded by the code on the page New Train Departure And Arrival RSS Feeds.

#!/usr/bin/perl -w ## Script to convert train departures from livedepartureboards.co.uk ## into RSS feeds. ## Takes the parameter "stationcode", as defined on the page nationalrail.co.uk ## page - http://www.nationalrail.co.uk/frameset.asp?location=ldb ## ## Robert Price - www.robertprice.co.uk - 10 July 2004 use strict; use CGI; use HTTP::Request; use LWP::UserAgent; use XML::RSS; ## Take the stationcode parameter, else default to COL (Colchester) my $CGI = new CGI; my $stationcode = $CGI->param('stationcode') || 'COL'; ## The URL we have to screen scrape for the information. my $url = 'http://www.livedepartureboards.co.uk/ldb/summary.aspx?T=' . $stationcode; ## Create our new browser, and pretend to be IE. my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); ## Get the data from the livedeartureboards.co.uk website. my $req = HTTP::Request->new(GET => $url); $req->header('Accept' => 'text/html'); my $res = $ua->request($req); if ($res->is_success) { my $page = $res->content; ## Get the station name and when the board was last updated. my ($updated) = ($page =~ m[Last updated:\r\n(.*?)\r\n]sg); my ($station_name) = ($page =~ m[<H1>Train Times for\r\n(.*?)\r\n]sg); ## Create our RSS data, update every 10 minutes. my $rss = new XML::RSS (version => '1.0'); $rss->channel( title => $station_name . ' Train Departures', link => 'http://www.nationalrail.co.uk/', description => 'Train times from ' . $station_name, syn => { updatePeriod => 'hourly', updateFrequency => '6' }, ); ## Loose nbsp's (they're wrong on the site so no ;) $page =~ s/\&nbsp//sg; ## Monster regex to extract the data. while ($page =~ m[<tr.*?>\r\n<td><a href="(.*?)">(.*?)</a></td>\r\n<td.*?>(.*?)</td>\r\n<td><span.*?>(.*?)</span></td>\r\n<td><a href=".*?">(.*?)</a></td>\r\n<td.*?>(.*?)</td>\r\n<td><span.*?>(.*?)</span></td>\r\n<td><a href=".*?">(.*?)</a></td>\r\n</tr>]sg) { ## Build a hash to store the information in. my $train = { 'link' => 'http://www.livedepartureboards.co.uk/ldb/' . $1, 'from' => $2, 'timetabled_arrival' => $3, 'expected_arrival' => $4, 'to' => $5, 'timetabled_departure' => $6, 'expected_departure' => $7, 'operator' => $8 }; ## Add the train departure to the RSS feed. $rss->add_item( title => ($train->{'timetabled_departure'} ? $train->{'timetabled_departure'} . ' to ' : '') . $train->{'to'} . ($train->{'expected_departure'} ? ( ' (' . $train->{'expected_departure'} . ')' ) : ''), link => $train->{'link'}, description => "From: " . $train->{'from'} . ",\n" . "Timetabled Arrival: " . $train->{'timetabled_arrival'} . ",\n" . "Expected Arrival: " . $train->{'expected_arrival'} . ",\n" . "To: " . $train->{'to'} . ",\n" . "Timetabled Departure: " . $train->{'timetabled_departure'} . ",\n" . "Expected Departure: " . $train->{'expected_departure'} . ",\n" . "Operator: " . $train->{'operator'} . "\n", ); } ## Return the RSS feed, ensuring we have the correct MIME type. print "Content-type: application/rdf+xml\n\n"; print $rss->as_string; }
Entered: 2004-07-13 09:57:33
Modified: 2004-12-08 10:19:43
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=387

Blog Changes And Trackbacks

I've been making a few changes to my blog this evening.

Firstly, all entries now link to their own pages, and aren't just aggregated into the monthly archive, though they can still be found there.

Secondly, I've added the ability for readers to issue a Trackback to the entries when they are linked to.

Trackbacks on this site are still experimental, but feel free to test them so I know if they are working or not. They are enabled for autodiscovery on the new individual pages, and I've also included the URL for cut and pasting (if needed) as part of the entries details.

Entered: 2004-07-11 00:25:13
Modified: 2004-07-11 00:25:46
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=386

Burn Baby Burn

One thing that always worries me travelling on London's tube network, is the lack of fire extinguishers.

I believe they were removed to stop people 'playing' and setting them off in the carriages when there wasn't a fire.

However, if I'm ever unfortunate to be stuck underground in a blazing carriage the last thing i'd want to find is that the train had no extinguishers incase people 'played' with them. I'd be more concerned with trying to put the fire out of escape alive with other passengers.

Surely it's best to put up with a bit of mess if it can help save a few lives.

This photo shows where the extinguisher should be on my current Central Line train.

MMS Blog image - /robblog/mmsimages/1089310962_1.jpg

PERMALINK - Burn Baby Burn
Mobile Blog Entry - Posted from an MMS enabled camera phone
Entered: 2004-07-08 19:22:42
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=385

Movie Industry Suffers Record Takings

This is taken straight from the Slashdot.org story Besieged Movie Industry Suffers Record Takings, but I've included it here as it's so well written.

The BBC is reporting that the movie industry, in yet another illustration of just how much damage the Internet is doing to the long-suffering members of the MPAA, has just endured a record breaking $1Billion dollar takings for the single month of June. Clearly there is a desperate need to tighten up copyright laws in the face of this huge mountain of cash that is literally being metaphorically syphoned into the studios' pockets. How will they survive?

We are constantly being told how the studios are going bankrupt due to piracy, but it would appear not with figures like these.

Entered: 2004-07-07 14:21:07
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=384

Free Olympic Travel In London?

I can't help but laugh at Lord Coe's plans for free Olympic travel in London.

The farce today just trying to travel from Oxford Circus to Liverpool Street when they had a few roads closed for a Formula 1 race showed how the existing transport infrastructure in London can't cope. In the end my journey took an extra hour, so God knows how long it would take if there were Olympic events taking place across the city.

However, Seb is promising the best planned and operated transport system in the history of the Olympics.

Just quite how everyone will cram into overpacked buses, tubes and trains waits to be seen.

However, there may be light at the end of the tunnel. Todays Evening Standard has a story about TfL's future London transport plans. It features lots of new tram, tube and rail lines.

Entered: 2004-07-06 21:59:02
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=383

Oxford Circus Closed For F1 Race

The usual cock up from London Underground was lack of notice of the closure of Oxford Circus tube station today.

I suppose common sense should of told me it would be shut due to the Formula One racing down Regent Street later.

However, being so used to queuing there due to overcrowding I just waited outside for 15 minutes, gradually moving forward as the people ahead gave up. Once at the front, a sign just below ground level said it was closed, and a member of staff said when asked that it would be shut for at least an hour, if not more.

Why doesn't London Underground advertise closures like this? It's known of it for a while, and no posters were up there this morning about it Also, why aren't the closure signs above ground level, so people further back can see and know not to bother waiting?

Oxford Street is a nightmare to move down and the bus i've managed to get on isn't moving due to crowds in the road.

MMS Blog image - /robblog/mmsimages/1089132515_1.jpg

Mobile Blog Entry - Posted from an MMS enabled camera phone
Entered: 2004-07-06 17:48:35
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=382

No New Dalek Stories

The BBC is reporting that there will be no Daleks in Doctor Who when it returns next year.

Negotiations between the BBC and the Terry Nation estate broke down due to issues over editorial control.

It's certainly a shame that the Doctor's most popular foe won't be appearing in the new series, but at least they are back in Big Finishes Dalek Empire audio series.

Entered: 2004-07-05 08:56:30
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=381