1#!/usr/bin/perl 2 3# Mark Palmer markpalmer@us.ibm.com 4 5use Cisco::IPPhone; 6use LWP; 7use CGI; 8 9$ua = LWP::UserAgent->new; 10$mytext = new Cisco::IPPhone; 11$error = new Cisco::IPPhone; 12$query = new CGI; 13 14my $host = "rainmaker.wunderground.com"; 15my $url = "/cgi-bin/findweather/getForecast"; 16$zip = $query->param('zip'); 17$completeurl = "http:\/\/$host\/$url?zip=$zip"; 18 19my $request = HTTP::Request->new(GET => $completeurl); 20my $response = $ua->request($request); 21 22if ($response->is_success) { 23 # It was successful, so parse the form 24 $lines = $response->content; 25 $city = $1 if $lines =~ /<title>Weather Underground:(.*) Forecast?</; 26if ($lines =~ /Temperature.*\n.*?(\d+).*\n.*Humidity.*\n.*?(\d+).*\n.*Dewpoint.*\n.*?(\d+).*\n.*Wind/) { 27 $tempf = $1; 28 $tempf .= " F"; 29 $humidity = $2; 30 $humidity .= "%"; 31 $dewpoint = $3; 32 $dewpoint .= " F"; 33} 34if ($lines =~ /Sunrise.*?(\d.+AM).*\n.*Sunset.*?(\d.+PM)/) { 35 $sunrise = $1; 36 $sunset = $2; 37} 38$mytext->Text( { Title => "Current Conditions", Prompt => "Select", 39 Text => "$city\nTemp: $tempf \nHumidity: $humidity\nDewpoint: $dewpoint\nSunrise/set: ${sunrise} ${sunset}" }); 40$mytext->AddSoftKeyItem( { Name => "Update", URL => "SoftKey:Update", 41 Position => "1" }); 42$mytext->AddSoftKeyItem( { Name => "Exit", URL => "SoftKey:Exit", 43 Position => "2" }); 44print $mytext->Content; 45} else { 46 $mytext->Text( { Title => "My Title", Prompt => "My Prompt", 47 Text => "Unable to access $completeurl" }); 48 $mytext->AddSoftKeyItem( { Name => "Update", URL => "SoftKey:Update", 49 Position => "1" }); 50 $mytext->AddSoftKeyItem( { Name => "Exit", URL => "SoftKey:Exit", 51 Position => "2" }); 52 print $mytext->Content; 53} 54 55__END__ 56