Back in 2002, a bunch of bureaucrats decided that the United States needed an advisory system so that all federal departments and agencies could communicate what the current threat condition was using the same definitions. Sounds like a good idea to me.
The average citizen can see what the current threat condition is by visiting certain government web sites. The web site for the Department of Homeland Security is a good example.
The Department of Homeland Security also provides a little-known web service which returns the threat condition in XML format so that you can do what you want with it. Let's write a function to retrieve and parse this information down to just the threat condition itself.
ASP
function getThreatLevel()
dim regEx
set regEx = new RegExp
with regEx
.Pattern = ".*\n.*CONDITION=""(.*)"" />"
.IgnoreCase = true
.Global = true
end with
dim xmlhttp
set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
xmlhttp.open "GET", "http://www.dhs.gov/dhspublic/getAdvisoryCondition", "False"
xmlhttp.send
getThreatLevel = regEx.replace(xmlhttp.responseText, "$1")
set xmlhttp = nothing
set regEx = nothing
end function
As is often the case, the PHP version requires a significantly less amount of code.
PHP
function getThreatLevel()
{
return eregi_replace('.*CONDITION="(.*)" />', '\1', file_get_contents("http://www.dhs.gov/dhspublic/getAdvisoryCondition"));
}
So now we have a string that contains just the word "ELEVATED" (or whatever the current threat level is at the moment; it's been at elevated for several years at the time of this writing). What can you do with it? Feed it into a switch statement and display an image is one possibility.
No comments:
Post a Comment