Created
May 8, 2013 19:55
-
-
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.
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 | |
| $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