Public feed #888791

Miscellany

public text v1 · immutable
Raw Edit
·published 2008-02-02 12:11 UTC
rendered paste body
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request;


my $browser = LWP::UserAgent->new;
my $URL = "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=$ARGV[0]";

sub get_weather()
{
	my $request = HTTP::Request->new(GET => $URL);
	my $response = $browser->request($request);
	if ($response->is_error()) {printf "%s\n", $response->status_line;}
	$contents = $response->content();
	if ( $contents =~ /<title>(.+)Conditions.&amp/) {
		print "$1-";
	}
  	else {
		if ( $contents =~ /<title>(.+)<\/title>/) {
			my @parse = split(/:/,$1);
			print "$parse[0]-";
		}
	}

	if ( $contents =~ /<nobr><b>(.+)<\/b>(.+)<\/nobr>/) {
		my @parse1 = split(/;/,$2);
		print " $1°$parse1[2] - ";
	}
	if ( $contents =~ /<nobr>(.+)<\/nobr><\/span><\/td>/) {
		print "Humidity: [$1] ";
	}
	if ( $contents =~ /<nobr><b>(.+)<\/b>(.+)km\/h<\/nobr>/) {
		printf "Wind Speed: [$1 km/h]\n";

	}

} 

get_weather();