Created
February 17, 2013 12:06
-
-
Save Jasper-Bekkers/4971230 to your computer and use it in GitHub Desktop.
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
<?php | |
// Settings: | |
// - METRO_ID is extracted from the sl.se url. This URL is for slussen departures | |
// http://realtid.sl.se/?id=177&epslanguage=sv&WbSgnMdl=9192-U2x1c3NlbiAoU3RvY2tob2xtKQ%3d%3d-_--_-_-_ | |
// the METRO_ID is 9192 | |
// | |
// - DEPARTURE_NAME is the station the metro you want is going to as it appears on the above URL eg. 'Hässelby str.' | |
// - DEPARTURE_NICKNAME just a friendly name to make th english tts api be able to pronounce your destination | |
// - API_KEY is the api key, you can get one at http://www.trafiklab.se | |
$METRO_ID = ; | |
$DEPARTURE_NAME = ''; | |
$DEPARTURE_NICKNAME = 'your destination'; | |
$API_KEY = ''; | |
header('Content-type: text/html; charset=utf-8'); | |
$subway = json_decode(file_get_contents("https://api.trafiklab.se/sl/realtid/GetDepartures.json?siteId=$METRO_ID&key=$API_KEY"), true); | |
$metros = $subway['Departure']['Metros']['Metro']; | |
foreach($metros as $metro) | |
{ | |
preg_match('/\d+ min|Kort tåg|\d+:\d+/', $metro['DisplayRow1'], $matches); | |
if($matches[0] == "Kort tåg") $say = "is departing now"; | |
else if(strstr($matches[0], "min")) $say = 'arrives in ' . str_replace('min', 'minutes', $matches[0]); | |
else if(strstr($matches[0], ":")) $say = 'arrives at ' . $matches[0]; | |
else $say = $metro['DisplayRow1']; | |
$split = explode(' ', $metro['DisplayRow1']); | |
$tostation = $split[2]; | |
if($split[2] == $DEPARTURE_NAME) | |
{ | |
$tostation = $DEPARTURE_NICKNAME; | |
echo "<audio src='http://tts-api.com/tts.mp3?q=" . urlencode('The metro to '. $tostation . ' ' . $say) . "' autoplay></audio>"; | |
break; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment