Skip to content

Instantly share code, notes, and snippets.

@alexbilbie
Created July 31, 2012 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbilbie/3215872 to your computer and use it in GitHub Desktop.
Save alexbilbie/3215872 to your computer and use it in GitHub Desktop.
Hubot phone search
#!/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