Skip to content

Instantly share code, notes, and snippets.

@KartikTalwar
Last active December 15, 2015 11:18
Show Gist options
  • Save KartikTalwar/5251659 to your computer and use it in GitHub Desktop.
Save KartikTalwar/5251659 to your computer and use it in GitHub Desktop.
<?php
$key = ''; // enter your api key here
function getLocations($key)
{
$url = "http://api.uwaterloo.ca/public/v1/?key=$key&service=APLocations";
$get = file_get_contents($url);
$json = json_decode($get);
return $json->response->data->Locations->result;
}
function getAPData($location, $key)
{
$url = "http://api.uwaterloo.ca/public/v1/?key=$key&service=APInfo&q=$location";
$get = file_get_contents($url);
$json = json_decode($get);
$points = $json->response->data->result;
$valid = array();
foreach($points as $point)
{
if(!empty($point->Latitude) && !empty($point->Longitude))
{
$valid[] = implode(', ', (array) $point);
}
}
return $valid;
}
function makeCSV($key)
{
$locations = getLocations($key);
$datapoints = array();
foreach($locations as $location)
{
$datapoints = array_merge($datapoints, getAPData($location, $key));
}
$keys = array('APName', 'ArubaAPModel', 'IPAddress', 'MACAddress', 'SecondaryMACAddress',
'BSSID', 'SSID', 'Location', 'Floor', 'Latitude', 'Longitude');
return implode(", ", $keys) . "\n" . implode("\n", $datapoints);
}
echo makeCSV($key);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment