-
Notifications
You must be signed in to change notification settings - Fork 0
/
getdata.php
56 lines (39 loc) · 1.33 KB
/
getdata.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
include('stations.inc');
$odataurl = 'http://traindata.dsb.dk/stationdeparture/opendataprotocol.svc/Queue()';
$uic = '8600' . $_POST['uic'];
$filter_elements = array(
'StationUic' => $uic,
'TrainType' => 'S-tog',
);
$elements = array();
foreach ($filter_elements as $key => $value) {
$elements[] = '(' . $key . ' eq \'' . $value . '\')';
}
$filter_string = implode(' and ', $elements);
$odataurl .= '?$filter=' . urlencode($filter_string);
$request = curl_init($odataurl . '&$format=json');
curl_setopt($request, CURLOPT_HEADER, array());
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($request);
$data = json_decode($output);
$data = reset($data);
$direction_output = array();
foreach ($data as $departure) {
$direction_output[$departure->Direction][] = array(
'line' => ucfirst(strtolower($departure->Line)),
'destination' => $departure->DestinationName,
'departure' => $departure->MinutesToDeparture,
);
}
$south = $direction_output['Syd'];
unset($direction_output['Syd']);
$direction_output['Syd'] = $south;
$output = array();
foreach ($direction_output as $direction => $data) {
$output[] = array('head' => str_replace(' st', '', $stationlist[$uic]['station']) . ' m. ' . strtolower($direction));
foreach ($data as $departure) {
$output[] = $departure;
}
}
print json_encode($output);