Created
July 31, 2012 10:21
-
-
Save alexbilbie/3215872 to your computer and use it in GitHub Desktop.
Hubot phone search
This file contains 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
#!/usr/bin/php | |
<?php | |
$vars = explode(' ', $argv[1]); | |
if ($vars[0] === 'phone') | |
{ | |
unset($vars[0]); // remove the "phone" bit | |
$search = implode(' ', $vars); | |
echo 'Searching the staff directory for "' . $search . '"...' . PHP_EOL . PHP_EOL; | |
$json_get = file_get_contents('http://phone.online.lincoln.ac.uk/search/json?q=' . urlencode($search)); | |
if ($json_get) | |
{ | |
$json = json_decode($json_get); | |
if (count($json->results) > 0) | |
{ | |
foreach ($json->results as $person) | |
{ | |
if ($person->phone === '') | |
{ | |
echo $person->fullname . ' (' . $person->division . ') : no number' . PHP_EOL; | |
} | |
else | |
{ | |
echo $person->fullname . ' (' . $person->division . ') : ' . $person->phone . PHP_EOL; | |
} | |
} | |
} | |
else | |
{ | |
echo '...no results found =['; | |
} | |
} | |
else | |
{ | |
echo '...search failed or timed out =['; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment