Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Prevents too many SQL Updates
- include("/home/brandanl/cad.brandanlasley.com/core/time.php");
- // Connect to MySQL Database
- include("/home/brandanl/ecw.brandanlasley.com/admin/FDS/database.php");
- $db_name = "pdx911";
- mysql_connect("$host", "$username", "$password")or die("cannot connect");
- mysql_select_db("$db_name")or die("cannot select DB");
- if ($Stop_Import == 0) {
- //http://www.monroecounty.gov/etc/911/rss.php
- // OREGON - Washington County - Clackamas County
- // Getting Random XML ID from WCCCA HTML
- $data = file_get_contents("http://208.71.205.35/PITS/");//thanks WCCCA!
- $pattern = "/id=\"hidXMLID\" value=\"([^\"]+)\"/";//looking for the rnd xml id#
- preg_match_all($pattern, $data, $xmlext);
- $url = "http://208.71.205.35/PITS/xml/fire_data_" . $xmlext[1][0] . ".xml";//putting together the secret xml url
- $xml = simplexml_load_file($url);
- // Find coordinates for the most recent event
- $data2 = file_get_contents("$url");
- preg_match_all("/lat=\"([^\"]+)\"/", $data2, $latout);//get the lat
- preg_match_all("/lng=\"([^\"]+)\"/", $data2, $lngout);//get the lon
- sql("TRUNCATE TABLE active_911_calls");
- $i = 0;
- while ($i <= sizeof($xml->marker)) {
- if ($i <= (sizeof($xml->marker) - 1)) {
- $vars = $xml->marker[$i]->attributes();
- $latt = $vars->lat;
- $long = $vars->lng;
- }
- $county=$xml->marker[$i]->AGENCY;// get first marker agency
- $id=$xml->marker[$i]->TWO_DIGIT_CALL_NO;// get call id#
- $call=$xml->marker[$i]->CALL_TYPE_FINAL_D;// get first marker call type
- $location=$xml->marker[$i]->LOCATION;// get first marker location
- $station=$xml->marker[$i]->BEAT_OR_STATION;// get first marker station
- $units=$xml->marker[$i]->UNITS;// get first marker units
- $priority=$xml->marker[$i]->PRIORITY;// get first marker prirorty
- $type=$xml->marker[$i]->TYPE;// get first marker type
- $callno=$xml->marker[$i]->CALL_NO;// get first marker type
- //cleans up the lat and lon
- $lati = str_replace('lat="','',$latt);
- $llatt = str_replace('"','',$lati);
- $longi = str_replace('lng="','',$long);
- $llonn = str_replace('"','',$longi);
- //this next section removes the "~" from the start of all the lines
- $cleancounty = str_replace('~','',$county);
- $cleancall = str_replace('~','',$call);
- $cleanstation = str_replace('~','',$station);
- $cleanlocation = str_replace('/',' / ',str_replace('~','',$location));
- $cleanunits = str_replace('~','',$units);
- $cleanid = str_replace('~','',$id);
- $cleanpriority = str_replace('~','',$priority);
- $cleantype = str_replace('~','',$type);
- $cleancallno = str_replace('~','',$callno);
- // $llatt . "+" . $llonn
- // Fliter Calls
- $cleancall = str_replace('MVA-','Multi-Vehicle ',$cleancall);
- $cleancall = str_replace('MVA','Multi-Vehicle ',$cleancall);
- $cleancall = str_replace('ACCID','Accident ',$cleancall);
- // End Filtering Calls
- //put the parts together for the twitter status line
- if ($cleancounty !== '') {
- if ($llatt == "") {
- $GoogleGPS = toCoordinates($cleanlocation) . ", OR";
- SQL("INSERT INTO active_911_calls values('$cleancallno', '$cleancounty', '$cleancall', '$cleanstation', '$cleanlocation', '$cleanunits', '$cleanid', '$cleanpriority', '$cleantype', '".$GoogleGPS."')");
- } else {
- SQL("INSERT INTO active_911_calls values('$cleancallno', '$cleancounty', '$cleancall', '$cleanstation', '$cleanlocation', '$cleanunits', '$cleanid', '$cleanpriority', '$cleantype', '$llatt', '$llonn')");
- }
- }
- $i++;
- }
- // NEW YORK
- $url = "http://www.monroecounty.gov/etc/911/rss.php";
- $rss = simplexml_load_file($url);
- if($rss)
- {
- $items = $rss->channel->item;
- foreach($items as $item)
- {
- $description = explode("at", $item->title);
- $cleancounty = str_replace('~','',$description[0]);
- $cleancall = str_replace('~','',$call);
- $cleanstation = str_replace('~','',$station);
- $cleanlocation = str_replace('/',' / ',str_replace('~','',$location));
- $cleanunits = str_replace('~','',$units);
- $GoogleGPS = toCoordinates($description[1] . ", NY");
- SQL("INSERT INTO active_911_calls values('".$item->pubDate."', 'monroeNY', '".$description[0]."', 'N/A', '".$description[1]."', '".$item->description."', 'N/A', 'N/A', 'F', '".$GoogleGPS."')");
- }
- }
- }
- // SQL Command Proccessor
- function SQL($command) {
- $sql="$command";
- $result=mysql_query($sql);
- }
- $retry = 0;
- function toCoordinates($address)
- {
- back:
- $bad = array(
- " " => "+",
- "," => "",
- "?" => "",
- "&" => "",
- "=" => ""
- );
- $address = str_replace(array_keys($bad), array_values($bad), $address);
- $data = new SimpleXMLElement(file_get_contents("http://maps.google.com/maps/geo?output=xml&q={$address}"));
- $coordinates = explode(",", $data->Response->Placemark->Point->coordinates);
- if ($coordinates[1] == '') {
- if ($retry == 10) {
- } else {
- sleep(.03);
- $retry++;
- goto back;
- }
- }
- return ($coordinates[1]."', '".$coordinates[0]);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement