Terror Alert Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tomcat7194
Forum Commoner
Posts: 48
Joined: Mon Jul 31, 2006 1:34 pm

Terror Alert Script

Post by Tomcat7194 »

Hey, I'm trying to find/make a script that will display the current US terror alert level as an integer value from 1-5.

As of yet, I haven't found a script that will do that. Does anyone know of one?

If such a script doesn't already exist, I figure I can modify an existing one. Most of the scripts out there now use Javascript to load an image that changes based on the current alert status. For example, this script http://www.terror-alert.com/getcode.html loads a js file with this code:

document.writeln('<A href="http://www.terror-alert.com"><IMG alt="Terror Alert Elevated" border=0 height=42 id=IMG3 SRC="http://www.terror-alert.com/images/Terr ... d.jpg"></a>');

Using PHP, is there a way that I could process that and get the current terror level based on the image url? My first thought would be to somehow use the "id=" thing in the image url, since it seems to indicate the terror level that the image matches with. I'm not good enough with PHP to know if that's possible--any ideas for how to do it? Or is there a completely different approach I should be taking?

Thanks in advance

Tom
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I have been looking for something like this for quite a while. The only thing that I have seen is someone's hack of an fopen() call to the DHS website, then stripping everything around their Terror Alert image, then copying the URL of the image and returning that to the calling PHP script. It is a dirty hack, but I don't think the DHS has offered an RSS or any other API to get at their terror alerts, which happen to be dynamic and updated by them.
Tomcat7194
Forum Commoner
Posts: 48
Joined: Mon Jul 31, 2006 1:34 pm

Post by Tomcat7194 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I think I actually may have found a solution to this problem. I just applied file_get_contents to the js file above, and then used a series of if statements to determine the value of the ID tage. Assuming that IMG1 = terror level 1, IMG2 = level 2, etc, this script should work. 

Here's the code:

Code: Select all

//terror alert
$terror_raw = file_get_contents('http://www.terror-alert.com/alert/status.jsc?id=1', 'r');
if (substr_count($terror_raw, 'IMG1') == 1) {
	$terror_working = 1;
	}
if (substr_count($terror_raw, 'IMG2') == 1) {
	$terror_working = 2;
	}
if (substr_count($terror_raw, 'IMG3') == 1) {
	$terror_working = 3;
	}
if (substr_count($terror_raw, 'IMG4') == 1) {
	$terror_working = 4;
	}
if (substr_count($terror_raw, 'IMG5') == 1) {
	$terror_working = 5;
	}
echo ("<br>Terror Level = $terror_working");
Tom


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Code: Select all

<?php
function getTerrorLevel($startingRating = 1) {
    $terror = file_get_contents('http://www.terror-alert.com/alert/status.jsc');
    $search = '<IMG alt="Terror Alert ';
    $pos['start']  = strpos($terror, $search) + strlen($search);
    $pos['length'] = strpos($terror, '"', $pos['start']-1) - $pos['start'];
    $result = substr($terror, $pos['start'], $pos['length']);
    $levels = array($startingRating => 'Low', 'Guarded', 'Elevated', 'High', 'Severe');
    $level = array_search($result, $levels);
    return $level;
}
?>
Last edited by Ollie Saunders on Tue Aug 01, 2006 2:12 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

I hate to tell you guys this but doing this is kind of a useless endeavor.

They have different terror alert levels for different cities and parts of the country now. The over all terror alert is basically useless anymore.

Then again then entire concept of the terror alert was flawed from the start anyway and is about as useful as earwax. You could talk to 1000 americans and would be lucky to find any who know what the level is and they would just make a guess. It was a panacea at the time just to make it look like the government was doing something. :D

Heck, you could just have your script randomly pick 3 or 4 each day and be just as accurate. :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PJ, please steer clear of political discussion.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

No need for you to post that as it wasn't political but reality.
Post Reply