-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructural.php
59 lines (46 loc) · 1.52 KB
/
structural.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
<?php
// $argv:
// 1 = trainnumber (letter(s) + number)
// 2 = from
// 3 = to
// 4 = crowding (0=empty, 1=in between, 2=busy)
if(count($argv) == 5) {
$curl = curl_init();
$url = "http://api.irail.be/vehicle/?id=BE.NMBS." . $argv[1];
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string($result);
$stops = $xml->stops;
$write = false;
$errorCheck = 0;
$text = "";
$crowding = "?";
foreach($stops->stop as $stop) {
if($stop->station == $argv[2]) {
if($errorCheck != 0) $errorCheck += 1;
$crowding = $argv[4];
$errorCheck += 1;
}
if($crowding != "?") {
if($stop->station == $argv[2]) {
$text .= $argv[1] . "," . $crowding . ",1," . $stop->station["URI"] . ",";
} else if($stop->station != $argv[3]) {
$text .= $stop->station["URI"] . "\n";
$text .= $argv[1] . "," . $crowding . ",1," . $stop->station["URI"] . ",";
} else {
$text .= $stop->station["URI"] . "\n";
}
}
if($stop->station == $argv[3] && $errorCheck == 1) {
$errorCheck += 1;
$crowding = "?";
}
}
if($errorCheck != 2) echo "Error: stations niet overlopen\n";
else $myfile = file_put_contents('structural.csv', $text.PHP_EOL, FILE_APPEND);
} else {
echo "Error: geef 4 argumenten\n";
}
?>