Advertisement
Brandan

Untitled

Dec 24th, 2012
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.85 KB | None | 0 0
  1. <?php
  2.  
  3. // Prevents too many SQL Updates
  4. include("/home/brandanl/cad.brandanlasley.com/core/time.php");
  5.  
  6. // Connect to MySQL Database
  7. include("/home/brandanl/ecw.brandanlasley.com/admin/FDS/database.php");
  8. $db_name = "pdx911";
  9. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  10. mysql_select_db("$db_name")or die("cannot select DB");
  11.  
  12. if ($Stop_Import == 0) {
  13.  
  14. //http://www.monroecounty.gov/etc/911/rss.php
  15.  
  16. // OREGON - Washington County - Clackamas County
  17.  
  18. // Getting Random XML ID from WCCCA HTML
  19. $data = file_get_contents("http://208.71.205.35/PITS/");//thanks WCCCA!
  20. $pattern = "/id=\"hidXMLID\" value=\"([^\"]+)\"/";//looking for the rnd xml id#
  21. preg_match_all($pattern, $data, $xmlext);
  22. $url = "http://208.71.205.35/PITS/xml/fire_data_" . $xmlext[1][0] . ".xml";//putting together the secret xml url
  23. $xml = simplexml_load_file($url);
  24.  
  25. // Find coordinates for the most recent event
  26. $data2 = file_get_contents("$url");
  27. preg_match_all("/lat=\"([^\"]+)\"/", $data2, $latout);//get the lat
  28. preg_match_all("/lng=\"([^\"]+)\"/", $data2, $lngout);//get the lon
  29.  
  30. sql("TRUNCATE TABLE active_911_calls");
  31. $i = 0;
  32. while ($i <= sizeof($xml->marker)) {
  33.     if ($i <= (sizeof($xml->marker) - 1)) {
  34.     $vars = $xml->marker[$i]->attributes();
  35.     $latt = $vars->lat;
  36.     $long = $vars->lng;
  37.     }
  38.     $county=$xml->marker[$i]->AGENCY;// get first marker agency
  39.     $id=$xml->marker[$i]->TWO_DIGIT_CALL_NO;// get call id#
  40.     $call=$xml->marker[$i]->CALL_TYPE_FINAL_D;// get first marker call type
  41.     $location=$xml->marker[$i]->LOCATION;// get first marker location
  42.     $station=$xml->marker[$i]->BEAT_OR_STATION;// get first marker station
  43.     $units=$xml->marker[$i]->UNITS;// get first marker units
  44.     $priority=$xml->marker[$i]->PRIORITY;// get first marker prirorty
  45.     $type=$xml->marker[$i]->TYPE;// get first marker type
  46.     $callno=$xml->marker[$i]->CALL_NO;// get first marker type
  47.    
  48.     //cleans up the lat and lon
  49.     $lati = str_replace('lat="','',$latt);
  50.     $llatt = str_replace('"','',$lati);
  51.     $longi = str_replace('lng="','',$long);
  52.     $llonn = str_replace('"','',$longi);
  53.    
  54.     //this next section removes the "~" from the start of all the lines
  55.     $cleancounty = str_replace('~','',$county);
  56.     $cleancall = str_replace('~','',$call);
  57.     $cleanstation = str_replace('~','',$station);
  58.     $cleanlocation = str_replace('/',' / ',str_replace('~','',$location));
  59.     $cleanunits = str_replace('~','',$units);
  60.     $cleanid = str_replace('~','',$id);
  61.     $cleanpriority = str_replace('~','',$priority);
  62.     $cleantype = str_replace('~','',$type);
  63.     $cleancallno = str_replace('~','',$callno);
  64.     // $llatt . "+" . $llonn
  65.    
  66.     // Fliter Calls
  67.     $cleancall = str_replace('MVA-','Multi-Vehicle  ',$cleancall);
  68.     $cleancall = str_replace('MVA','Multi-Vehicle ',$cleancall);
  69.     $cleancall = str_replace('ACCID','Accident ',$cleancall);
  70.    
  71.     // End Filtering Calls
  72.    
  73.  
  74.     //put the parts together for the twitter status line
  75.     if ($cleancounty !== '') {
  76.     if ($llatt == "") {
  77.     $GoogleGPS = toCoordinates($cleanlocation) . ", OR";
  78.     SQL("INSERT INTO active_911_calls values('$cleancallno', '$cleancounty', '$cleancall', '$cleanstation', '$cleanlocation', '$cleanunits', '$cleanid', '$cleanpriority', '$cleantype', '".$GoogleGPS."')");
  79.     } else {
  80.     SQL("INSERT INTO active_911_calls values('$cleancallno', '$cleancounty', '$cleancall', '$cleanstation', '$cleanlocation', '$cleanunits', '$cleanid', '$cleanpriority', '$cleantype', '$llatt', '$llonn')");
  81.     }
  82.     }
  83.     $i++;
  84. }
  85.  
  86. // NEW YORK
  87. $url = "http://www.monroecounty.gov/etc/911/rss.php";
  88. $rss = simplexml_load_file($url);
  89. if($rss)
  90. {
  91. $items = $rss->channel->item;
  92. foreach($items as $item)
  93. {
  94. $description = explode("at", $item->title);
  95.  
  96. $cleancounty = str_replace('~','',$description[0]);
  97. $cleancall = str_replace('~','',$call);
  98. $cleanstation = str_replace('~','',$station);
  99. $cleanlocation = str_replace('/',' / ',str_replace('~','',$location));
  100. $cleanunits = str_replace('~','',$units);
  101. $GoogleGPS = toCoordinates($description[1] . ", NY");
  102. SQL("INSERT INTO active_911_calls values('".$item->pubDate."', 'monroeNY', '".$description[0]."', 'N/A', '".$description[1]."', '".$item->description."', 'N/A', 'N/A', 'F', '".$GoogleGPS."')");
  103. }
  104. }
  105. }
  106. // SQL Command Proccessor
  107. function SQL($command) {
  108.         $sql="$command";
  109.         $result=mysql_query($sql);
  110. }
  111. $retry = 0;
  112.     function toCoordinates($address)
  113. {
  114. back:
  115.     $bad = array(
  116.         " " => "+",
  117.         "," => "",
  118.         "?" => "",
  119.         "&" => "",
  120.         "=" => ""
  121.     );
  122.     $address = str_replace(array_keys($bad), array_values($bad), $address);
  123.     $data = new SimpleXMLElement(file_get_contents("http://maps.google.com/maps/geo?output=xml&q={$address}"));
  124.     $coordinates = explode(",", $data->Response->Placemark->Point->coordinates);
  125.    
  126.     if ($coordinates[1] == '') {
  127.     if ($retry == 10) {
  128.     } else {
  129.     sleep(.03);
  130.     $retry++;
  131.     goto back;
  132.     }
  133.     }
  134.    
  135.     return ($coordinates[1]."', '".$coordinates[0]);
  136. }  
  137. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement