Seattle 911 scanner on Tropo for the hackathon
August 22nd, 2010 by Adam KalseyFor the Gnomedex hackathon we sponsored this weekend, I spent most of my time helping out teams who were building things using Tropo. But mid-morning today, inspiration struck for my own project. It’s not huge, so I was able to hack it together quickly and it’s a great sample app.
Remember police scanners? You can listen to live radio traffic between police cars. Some people do it for profit, like news reporters or ambulance chasers. Others do it for fun, just to hear what’s going on. The City of Seattle, one of our sponsors publishes their fire department 911 calls in near-real time using services from Socrata, another hackathon sponsor. So I wrote up an app that emulates a police scanner, using 911 dispatches as a data source.
Call a phone number, and Tropo will fetch the current list of 911 data from Socrata and play the incidents over the phone. For demo purposes, we’re only fetching data every 15 minutes and we’re getting any calls from the last 10 hours.
You can grab the code from Github or read it below.
<?php
answer();
sleep(2);
say ('Welcome to the Seattle <say-as interpret-as="vxml:digit">911</say-as> scanner.');
$timer = time();
$data = fetchIncidents();
if (count($data) == 0) {
say("http://hosting.tropo.com/37423/www/audio/beep-7.mp3";);
}
while(1) {
$data = fetchIncidents();
foreach ($data as $incident) {
say("<speak><paragraph xml:lang='en-us-fmj'>At <say-as interpret-as='address'>{$incident[8]}</say-as> an {$incident[9]}.</paragraph></speak>");
$timer = time();
}
$currTime = time();
if ($currTime - $timer > 30) {
say("http://hosting.tropo.com/37423/www/audio/beep-7.mp3";);
}
sleep(900);
}
function fetchIncidents() {
$url = "http://data.seattle.gov/api/views/INLINE/rows.json?method=index";;
$time = time() - 360000;
$data = '{"name":"Seattle Real Time Fire 911 Calls","query":{"orderBys":[{"expression":{"columnId": 2354168,"type":"column"},"ascending": false}],"filterCondition":{"value":"AND","children": [{"children":[{"columnId":2354168,"type":" column"},{"value":' . $time . ',"type":"literal"}],"value":" GREATER_THAN","type":"operator"}],"type":" operator"}},"originalViewId": "kzjm-xkqj"}';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$json = curl_exec ($ch);
curl_close($ch);
$data = json_decode($json, true);
return $data['data'];
}
?>
Related posts:
