Created
May 5, 2011 19:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/</</g; | |
$rss =~ s/>/>/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