Skip to content

Instantly share code, notes, and snippets.

@Pet3ris
Created May 5, 2011 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pet3ris/957689 to your computer and use it in GitHub Desktop.
Save Pet3ris/957689 to your computer and use it in GitHub Desktop.
Perl Cambridge (DTG rooftop http://www.cl.cam.ac.uk/research/dtg/weather/) weather data retreiver
#!/usr/bin/perl
# Usage
# camweather
# camweather Wind speed
# ..etc.
use LWP::Simple;
# Get raw RSS and beautify
$rss = get("http://www.cl.cam.ac.uk/research/dtg/weather/rss.xml");
$rss =~ s/&lt;/</g;
$rss =~ s/&gt;/>/g;
# Parse data
%data = ();
while ($rss =~ m/<tr><td>([^<]+)<\/td><td>([^<]+)<\/td><\/tr>/g) {
if ($#ARGV == -1) {
print "$1 is $2\n";
}
$data{$1} = $2;
}
# Display individual data
if ($#ARGV + 1 > 0) {
$output = $data{join(' ', @ARGV)};
print "$output";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment