Skip to content

Instantly share code, notes, and snippets.

@jhuesser
Created September 18, 2018 13:54
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 jhuesser/812af5b08996e4e112334362804d64fc to your computer and use it in GitHub Desktop.
Save jhuesser/812af5b08996e4e112334362804d64fc to your computer and use it in GitHub Desktop.
A quick and dirty json parser for opentransportdata.ch to use it with siri shortcuts
<?php
$departure = "8573710"; // ID of departure
$destination = "8503504"; // ID of destination
// use param transportations[] to filter transport type (train, tram, bus, etc.
$url = "http://transport.opendata.ch/v1/connections?from=". $departure . " . &to=" . $destination . "&date=" . date('Y-m-d');
$result = json_decode(file_get_contents($url));
// connections[0] seems to be to early, a quick and dirty fix
$arrival = $result->connections[1]->to->arrivalTimestamp;
$date = strtotime($arrival);
echo date("d.m.y H:i",$arrival);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment