-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.php
89 lines (77 loc) · 2.71 KB
/
cli.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
<?php
/**
* User: ms
* Date: 28.08.15
* Time: 23:34
* @see this ruby application https://github.com/rmoriz/mvg-live/blob/master/lib/mvg/live.rb
*
* Departures
* http://www.mvg-live.de/ims/dfiStaticAnzeige.svc?haltestelle=Karl-Theodor-Stra%DFe&ubahn=checked&bus=checked&tram=checked&sbahn=checked
*
* Select Station
* http://www.mvg-live.de/ims/dfiStaticAuswahl.svc?haltestelle=Karl&ubahn=checked&bus=checked&tram=checked&sbahn=checked
*/
use Mvg\Parser\Html\Departures;
use Mvg\Parser\Html\Stations;
use Mvg\TextOutput\Departures as TextOutputDepartures;
use Mvg\TextOutput\Stations as TextOutputStations;
use Mvg\Factories\Departures as DeparturesFactory;
use Mvg\RequestHandler\Html\HttpPostNewsTicker;
use Mvg\RequestHandler\Html\HttpGetDepartures;
use Mvg\TextOutput\NewsTicker as NewsTickerOutput;
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
try {
$opts = new Zend\Console\Getopt(
array(
'news|n' => 'Show news about Interferences',
'stations|s=s' => 'Departure Stations - separate multiple stations with ;',
'ends|e=s' => 'end of lines - separate multiple stations with ;'
)
);
$opts->parse();
} catch (Zend\Console\Exception\RuntimeException $e) {
echo $e->getUsageMessage();
exit;
}
if (null === $opts->getOption('s')) {
echo $opts->getUsageMessage();
exit;
}
//Stations
$stationString = trim($opts->getOption('s'));
$searchForStations = explode(';', $stationString);
//End of Lines
if (null !== $opts->getOption('e')) {
$endStationString = trim($opts->getOption('e'));
$filterForStations = explode(';', $endStationString);
} else {
$filterForStations = array();
}
foreach ($searchForStations as $searchForStation) {
$searchForStation = trim($searchForStation);
$http = new HttpGetDepartures('http', 'www.mvg-live.de', 'ims/dfiStaticAuswahl.svc');
$result = $http->getDeparturesForStation($searchForStation);
$parser = new Departures($result);
$departures = $parser->getDepartures();
if (0 === count($departures)) {
echo "Station '" . $searchForStation . "' unknown\n";
echo "Did you mean?\n";
$stationParser = new Stations($result);
echo (new TextOutputStations($stationParser))->getOutput();
} else {
$factory = new DeparturesFactory($parser);
echo (new TextOutputDepartures($factory, $filterForStations))->getOutput();
}
}
//Display news from the ticker
if (true === $opts->getOption('n')) {
$responseForNewsTicker = (new HttpPostNewsTicker())->doPostRequest();
$newsTickerParser = new \ Mvg\Parser\Html\NewsTicker($responseForNewsTicker);
$interferences = $newsTickerParser->getInterferences();
if (0 < count($interferences)) {
echo "Interferences\n";
echo (new NewsTickerOutput($newsTickerParser))->getOutput();
} else {
echo "No Interferences\n";
}
}