Links for 2007-10-28
- Mr Emap wants another Smash Hit - Telegraph An interview with Sir David Arculus, who is bidding to become chairman of Emap
Here are Rob's Blog entries for October 2007.
Blog entries for other months can be found in the main blog index.
For the Q Awards 2007, we wanted to have minute by minute blogging.
We used Movable Type for the website, but didn't want to have to rely on having a laptop available to blog from, so blogging from a mobile phone was the approach we took.
Originally we looked at Twitter for this, but we worried about connection speed. We also looked at Nokia Lifeblog, while good, it doesn't really allow for just headline posting. Finally, we took the custom code approach.
Movable Type has an Atom interface, it's what Nokia Lifeblog uses. This lets us post articles, so all we needed was a suitable client. Thankfully, using Perl, there is XML::Atom::Client.
Ben Hammersley provides an great tutorial on using the Atom API in Movable Type.
My code needed to take a line of text and post automatically to Movable Type in a certain category (called "livefeed"). I built a really simple HTML page that could be used by any internet enabled phone. It had one text box and one submit button. Copy entered here and submitted would appear in the Movable Type blog automatically.
I needed some glue Perl code behind this page to make this happen. It turned out to be really simple, and here's the core functionality. I won't bore you with CGI handling or display code, just the Atom meat.
my $api = XML::Atom::Client->new;
$api->username($username);
$api->password($password);
my $dc = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/');
my $entry = XML::Atom::Entry->new;
$entry->title($title);
$entry->content('');
$entry->set($dc, 'subject', 'livefeed');
my $edituri = $api->createEntry($posturl, $entry);
if ($edituri) {
## posted ok
} else {
## not posted, $api->errstr has the error message;
}
This code assumes you have a few variables in place, those are
Movable Type has two different passwords per user, it is important we use the webservices password and not the users normal Movable Type password.
Now we were posting and creating entries each post, we wanted to show them all on one page. my collegue Ross wrote this block of code to display the posts.
<MTEntries category="livefeed">
<li>
<MTIfNonEmpty tag="EntryTitle">
<p class="time"><$MTEntryDate format="%I:%M %p"$></p>
<p><$MTEntryTitle$></p>
</MTIfNonEmpty>
</li>
</MTEntries>
This turned out to be a nice, fast solution to getting content up quickly on the day.
We had to setup and run a webcam for the Q Awards red carpet earlier this week.
The original plan was to have an old Axis ethernet webcam, connected to a wifi network using a Dlink bridge. After a nightmare of not being able to get the Dlink to work, we gave up and went for a USB webcam connected to a laptop approach.
I had to write some software to handle the capture of the image and the upload to the webserver. Because we wanted to do a few custom things on the way we weren't able to use out of the box software.
I'll post on how to use a webcam with .NET another time. What I wanted to document was how to upload a file using .NET to a LAMP server.
It turns out to be easier than I thought for .NET, one line of code can achieve this using the My.Computer.Network.UploadFile Method.
For example, to upload test.txt to http://www.robertprice.co.uk/asp_upload.pl we can do the following (in Visual Basic)...
My.Computer.Network.UploadFile("C:\test.txt","http://www.robertprice.co.uk/asp_upload.pl")
Now we need some code at the other end to store this upload. As I was building a webcam application, the uploaded file, an image in this case, was always overwritten.
The uploaded .NET file uses an bog standard HTTP upload as described in RFC 1867.
If we use Perl to read this file, we can use the standard CGI.pm module to do most of the hard work for us.
The uploaded file is passed a parameter called file, so we can create a CGI object and get a reference to this using the param method. Once we have this, we can treat it as a filehandle and read the date off it. Then all we have to do is to write it out to a file.
The following code achieves this.
#!/usr/bin/perl -w
use strict;
use CGI.pm;
my $CGI = new CGI;
my $file = $CGI->param('file');
open(FILE, ">/path/to/my/file/test.txt") or die $!;
while(<$file>) {
print FILE $_;
}
close(FILE);
print "Content-type: text/html\n\n";
print "OK\n";
I've been working at this years Q Awards.
Look out for content i'm posting via mobile and wireless on the official website, q4music.com.

Here's a picture of me with my new favourite twins, Sam and Amanda of Big Brother fame.
As you may have read, i built the website for Heat Radio so was invited along for tonight's launch party.
I have to say, both Sam and Amanda are very friendly, beautiful and genuine people. After posing for a photo they even stopped for a dance with me.
Cheeky girls move over, Samanda are my new favourite twins.
