Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- //WashCo_FireMed & ClackCo_FireMed Twitter Feed Script
- //Version 2.0.1
- // This is my attempt to make a cross compatible script with the old version of PITSv1 PHP by Gary Kee - gary.kee@moonrize.com - twitter.com/fractal74
- // Setting
- $Use_Google_API_To_Get_Geo_Coordinates = 0;
- $Use_Twitter = 0;
- $Print_Debug = 1;
- $WCCCA_Version = 2;
- $uname = 'washco_firemed'; //twitter login name for washco
- $unamec = 'clackco_firemed'; //twitter login name for clackco
- $pwd = 'PASSWORD'; //twitter password
- $twitter_url = 'http://twitter.com/statuses/update.xml'; //twitter api url
- // Ignore WCCCA PITSv2 HTML Errors (probably should fix)
- error_reporting(E_ERROR | E_PARSE);
- // Download WCCCA PITSv2 full CAD site
- $HTML = file_get_contents("http://www.wccca.com/PITSv$WCCCA_Version/");
- // Extract Call and filter to show only call infomation
- // WCCCA:
- $WCCCA_Calls = (Seperate_Calls($HTML, 0));
- // CCOM:
- $CCOM_Calls = (Seperate_Calls($HTML, 1));
- $Raw_WCCCA_Calls = split("\n", $WCCCA_Calls);
- $Raw_CCOM_Calls = split("\n", $CCOM_Calls);
- // Add County infomation for WCCCA
- $converted_wccca_calls;
- foreach ($Raw_WCCCA_Calls as $call) {
- if (!empty($call)) {
- $converted_wccca_calls .= "County: W Call:" . $call . "\n";
- } //!empty($call)
- } //$Raw_WCCCA_Calls as $call
- // Add County infomation for CCOM
- $converted_ccom_calls;
- foreach ($Raw_CCOM_Calls as $call) {
- if (!empty($call)) {
- $converted_ccom_calls .= "County: C Call:" . $call . "\n";
- } //!empty($call)
- } //$Raw_CCOM_Calls as $call
- // Combind CCOM and WCCCA
- $Total_calls = $converted_ccom_calls . $converted_wccca_calls;
- // Split Total calls for looping
- $raw_calls = split("\n", $Total_calls);
- // Start the call loop
- foreach ($raw_calls as $call) {
- if (!empty($call)) {
- // Get County
- $county = explode(' ', $call);
- $cleancounty = $county[1];
- // Get Station
- $station = explode('Time: ', $call);
- $station1 = explode(' ', $station[1]);
- $cleanstation = $station1[5];
- // Get Agency
- $agency = $station1[4];
- $cleanagency = str_replace("/", "", $agency);
- // Get Call
- $raw_call = split("Call: ", $call);
- $raw_call2 = split(" Address:", $raw_call[1]);
- $cleancall = $raw_call2[0];
- // Get Address
- $raw_address = split("Address: ", $call);
- $raw_address1 = split(" Time:", $raw_address[1], 2);
- $cleanlocation = preg_replace('/\W\w+\s*(\W*)$/', '$1', $raw_address1[0]);
- // Get GUID
- $raw_guid = str_replace("$cleanlocation", "", $raw_address1[0]);
- $cleanguid = str_replace(' ', '', $raw_guid);
- // Get Units
- $raw_units = split(" Time:", $call);
- $raw_units1 = split("/", $raw_units[1]);
- $raw_units2 = split("- ", $raw_units1[1]);
- $cleanunits = $raw_units2[1];
- if ($Use_Google_API_To_Get_Geo_Coordinates == 1) {
- $raw_geocord = getgeoloc($cleanlocation, $cleancounty);
- $cleangeocord = split(",", $raw_geocord);
- $llatt = $cleangeocord[0];
- $llonn = $cleangeocord[1];
- } //$Use_Google_API_To_Get_Geo_Coordinates == 1
- if (!empty($cleancounty)) {
- if ($Print_Debug == 1) {
- print("County: $cleancounty Call: $cleancall Address: $cleanlocation Units: $cleanunits Agency: $cleanagency Station: $cleanstation GUID $cleanguid\n");
- } //$Print_Debug == 1
- if ($Use_Twitter == 1) {
- //build a google maps url with an info bubble
- $map = 'http://maps.google.com/maps?z=12&q=' . $llatt . "+" . $llonn . "+(" . $cleancall . "," . $cleanlocation . ", Units: " . $cleanunits . ")";
- //change the google map url to a tiny url (actually is.gd ur because it's smallerl) and change the spaces in the $map url to %20 so there is no bad http requests
- $mapfixed = rawurlencode($map);
- $tiny_url = file_get_contents("http://is.gd/api.php?longurl=" . $mapfixed);
- //put the parts together for the twitter status line
- $status = $cleancall . " | " . $cleanlocation . " | Units: " . $cleanunits . " | " . $tiny_url; //assemble status for twitter
- if ($cleancounty == "W") //if washington county, then post to washco_firemed
- {
- $curl_handle = curl_init();
- curl_setopt($curl_handle, CURLOPT_URL, "$twitter_url");
- curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
- curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl_handle, CURLOPT_POST, 1);
- curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$status");
- curl_setopt($curl_handle, CURLOPT_USERPWD, "$uname:$pwd");
- $buffer = curl_exec($curl_handle);
- curl_close($curl_handle);
- if (empty($buffer)) {
- echo '<br/>Fail-WC';
- } //empty($buffer)
- else {
- echo $status;
- }
- } //$cleancounty == "W"
- elseif ($cleancounty == "C") //if clackamas county, then post to clackco_firemed
- {
- $curl_handle = curl_init();
- curl_setopt($curl_handle, CURLOPT_URL, "$twitter_url");
- curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
- curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl_handle, CURLOPT_POST, 1);
- curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$status");
- curl_setopt($curl_handle, CURLOPT_USERPWD, "$unamec:$pwd");
- $buffer = curl_exec($curl_handle);
- curl_close($curl_handle);
- if (empty($buffer)) {
- echo '<br/>Fail-CC';
- } //empty($buffer)
- else {
- echo $status;
- }
- } //$cleancounty == "C"
- } //$Use_Twitter == 1
- } //!empty($cleancounty)
- } //!empty($call)
- } //$raw_calls as $call
- exit;
- function Seperate_Calls($HTML, $County)
- {
- $dom = new DOMDocument();
- $dom->loadHTML($HTML);
- $xpath = new DOMXPath($dom);
- // Switch between WCCCA/CCOM
- if ($County == 0) {
- $tags = $xpath->query('//div[@id="wccca-incidents"]');
- } //$County == 0
- else {
- $tags = $xpath->query('//div[@id="ccom-incidents"]');
- }
- // For each call delete all the massive amount of blank spaces and new lines.
- foreach ($tags as $tag) {
- $calls = preg_replace('/\s+/', ' ', $tag->textContent);
- } //$tags as $tag
- // Seperate the calls (since we removed all the \n's)
- $Filtered_Calls = split("Call Type:", $calls);
- // Loop though seperated calls and recombind them into a list, then add a new line to them for easier processing.
- foreach ($Filtered_Calls as $call) {
- $Call_dump .= $call . "\n";
- } //$Filtered_Calls as $call
- // Remove any unintentional blank spaces that may occur from this.
- $Call_dump = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", $Call_dump);
- // Return the calls.
- return ($Call_dump);
- }
- function getgeoloc($address, $county)
- {
- $prepAddr = str_replace(' ', '+', $address);
- $prepAddr = str_replace('+and+', '/', $prepAddr);
- $prepAddr = str_replace('S ', '', $prepAddr);
- if ($county == "C") {
- $prepAddr = $prepAddr . "+Clackamas+Oregon";
- } //$county == "C"
- else {
- $prepAddr = $prepAddr . "+Washington+Oregon";
- }
- $geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=' . $prepAddr . '&sensor=false');
- $output = json_decode($geocode);
- $latitude = $output->results[0]->geometry->location->lat;
- $longitude = $output->results[0]->geometry->location->lng;
- return ($latitude . "," . $longitude);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement