Last active
December 15, 2015 11:18
-
-
Save KartikTalwar/5251659 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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