Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Homeland Security Threat Level

by pbeckingham (Parson)
on Aug 12, 2005 at 14:56 UTC ( #483294=CUFP: print w/ replies, xml ) Need Help??

Displays the Department of Homeland Security threat level, in color. This was just a little CGI I wrote to make a point. Note that I do not advocate parsing XML with regular expressions, except in trivial cases like this.

#! /usr/bin/perl -w use strict; use LWP::UserAgent; my $level = 'Unknown'; my %colors = ( 'Unknown' => '#808080', 'Low' => '#63cf63', 'Guarded' => '#009aff', 'Elevated' => '#ffcf00', 'High' => '#ff6500', 'Severe' => '#ff0000', ); my $userAgent = new LWP::UserAgent; my $request = new HTTP::Request GET => 'http://www.dhs.gov/dhspublic/g +etAdvisoryCondition'; my $response = $userAgent->request ($request); $level = ucfirst lc $1 if $response->is_success && $response->content =~ /CONDITION="([^"]*)"/; print qq{Content-type: text/html <html> <body style="background-color:$colors{$level}"> <h3 style="color:#000000">$level</h3> </body> </html> }; exit 0;



pbeckingham - typist, perishable vertebrate.

Comment on Homeland Security Threat Level
Download Code
Re: Homeland Security Threat Level
by b10m (Vicar) on Aug 12, 2005 at 20:52 UTC

    Shouldn't that be more like this?

    #!/usr/bin/perl use strict; use LWP::Simple; my $level; my %colors = ( 'Unknown' => '#808080', 'Low' => '#63cf63', 'Guarded' => '#009aff', 'Elevated' => '#ffcf00', 'High' => '#ff6500', 'Severe' => '#ff0000', ); if(get('http://www.whitehouse.gov/president/') =~ /George W. Bush/i) { my @levels = ('Elevated', 'High', 'Severe'); $level = $levels[int(rand @levels)]; } else { $level = get('http://www.dhs.gov/dhspublic/getAdvisoryCondition'); $level =~ s/^.*CONDITION="([^"]+)".*$/\L\u$1/s; } print qq{Content-type: text/html <html> <body style="background-color:$colors{$level}"> <h3 style="color:#000000">$level</h3> </body> </html> };
    --
    b10m

    All code is usually tested, but rarely trusted.
Re: Homeland Security Threat Level
by Your Mother (Canon) on Aug 12, 2005 at 22:38 UTC

    ++ to b10m and a different grab, just for fun.

    use LWP::Simple; use XML::Simple; my $xml = XMLin ( get 'http://www.dhs.gov/dhspublic/getAdvisoryCondition' ); print $xml->{CONDITION}, $/;

      And since we're on the topic, I tender an algorithm I've been working day and night on for the last 4 years which I feel is a drastic improvement to the federal government's own byzantine system for determining the current threat level. I will apply for a patent over the weekend.

      my @levels = qw( Low Guarded Elevated High Severe ); print "Current Alert Level: ", $levels[rand@levels], $/;
Re: Homeland Security Threat Level
by phroggy (Monk) on Aug 14, 2005 at 00:32 UTC
    Have you noticed that the nationwide threat level hasn't changed from Elevated (yellow) in a few years?
    perl -e '($,,@_)=("er",",\n","l Hack"," P","Just anoth"); print reverse @_;'
Re: Homeland Security Threat Level
by gellyfish (Monsignor) on Aug 15, 2005 at 18:32 UTC

    Anyone else but you will probably want to remove the

    $userAgent->proxy (http => 'http://na6v13a01.fmr.com:8000');
    or alter it as appropriate.

    /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://483294]
Approved by thor
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-11-23 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (127 votes), past polls