-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathovinfo.php
121 lines (106 loc) · 2.73 KB
/
ovinfo.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<html>
<head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
<style>
body {
background-color: white;
}
th {
font-family: Arial, Helvetica;
color:blue;
font-size: 26px;
text-align: left;
}
.tbheader {
background-color:blue;
color: white;
}
.tbhalte {
font-size: 16px;
}
</style>
</head>
<body>
<table>
<tr class="tbheader">
<th class="tbheader">Tijd</th>
<th class="tbheader">  Bus</th>
<th class="tbheader">  Richting</th>
<th class="tbheader">Halte</th>
</tr>
<?php
///
/// Get data from v0.ovapi.nl and put it in a array.
/// tpc is TimingPoint code. Find it on: https://drgl.nl/
///
date_default_timezone_set('Europe/Amsterdam');
$busstop="65150930,65150940,65151250";
error_reporting(E_ALL);
$edtime=array();
$linenumber=array();
$destinationtimes=array();
$dtime=array();
$alltrips=array();
$c=0;
$count=0;
$maxrows=8;
/// Get data function
function getOVdata($tpc) {
$contents = file_get_contents('http://v0.ovapi.nl/tpc/'.$tpc);
$contents = utf8_encode($contents);
$results = json_decode($contents,true);
$sendOVdata = $results;
///
/// Return all data
///
return $sendOVdata;
};
$OVdata=getOVdata($busstop);
foreach ($OVdata as $data1)
{
foreach ($data1["Passes"] as $data2)
{
$alltrips[$c]['Line']=$data2['LinePublicNumber'];
$alltrips[$c]['Destination']=$data2['DestinationName50'];
$alltrips[$c]['ExpectedAT']=date("U",strtotime($data2['ExpectedArrivalTime']));
$alltrips[$c]['TargetAT']=date("U",strtotime($data2['TargetArrivalTime']));
$alltrips[$c]['TimingPointName']=$data2['TimingPointName'];
$c=$c+1;
};
};
usort($alltrips, function ($a, $b) { return ($a['TargetAT'] - $b['TargetAT']);});
foreach ($alltrips as $row) if ($count<$maxrows)
{
foreach ($row as $field)
{
$expectedarrivaltime = $row['ExpectedAT'];
$targettime = $row['TargetAT'];
$delayed = (($expectedarrivaltime-$targettime)/60);
$targettime=date("H:i",$targettime);
$destination = $row['Destination'];
$linenumber = $row['Line'];
$tpname = $row['TimingPointName'];
$delayed=round(intval($delayed),0);
if ($delayed!=0)
{
if ($delayed<0)
{
$delayed="<b style=\"color: darkgreen;\">".$delayed."</b>";
}
else
{
$delayed="<b style=\"color: red;\">+".$delayed."</b>";
}
}
else
{
$delayed="";
};
};
echo "<div style=\"font-family: Arial, Helvetica; color:blue; font-size: 18px;\"><tr><th><i class=\"far fa-clock\"></i> ".$targettime." ".$delayed."</th><th>  <i class=\"fas fa-bus\"></i> ".$linenumber."</th><th>  ".$destination."</th><th class=\"tbhalte\">".$tpname."</tr></div>";
$count+=1;
};
?>
</table>
</body>
</html>