Skip to content

Instantly share code, notes, and snippets.

@justinanderson
Created May 8, 2013 19:55
Show Gist options
  • Select an option

  • Save justinanderson/5543156 to your computer and use it in GitHub Desktop.

Select an option

Save justinanderson/5543156 to your computer and use it in GitHub Desktop.
Example of how to get and display basic shuttle info from the MIT Mobile API.
<?php
$json = file_get_contents('http://m.mit.edu/api/?module=shuttles&command=routeInfo&id=tech');
$route = json_decode($json);
function hasID($stop)
{
return $stop->id=='tangwest';
}
$filteredStops = array_filter($route->stops, "hasID");
$stop = array_shift($filteredStops);
$routeName = $route->title;
$stopName = $stop->title;
$prediction = round(($stop->next - time()) / 60);
?>
<html>
<head>
<title>MIT Shuttles</title>
</head>
<body>
<h2><?php echo $routeName; ?></h2>
<h1><?php echo $stopName; ?></h1>
<h1><?php echo "{$prediction} mins"; ?></h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment