1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User: ms |
4
|
|
|
* Date: 28.08.15 |
5
|
|
|
* Time: 23:34 |
6
|
|
|
* @see this ruby application https://github.com/rmoriz/mvg-live/blob/master/lib/mvg/live.rb |
7
|
|
|
* |
8
|
|
|
* Departures |
9
|
|
|
* http://www.mvg-live.de/ims/dfiStaticAnzeige.svc?haltestelle=Karl-Theodor-Stra%DFe&ubahn=checked&bus=checked&tram=checked&sbahn=checked |
|
|
|
|
10
|
|
|
* |
11
|
|
|
* Select Station |
12
|
|
|
* http://www.mvg-live.de/ims/dfiStaticAuswahl.svc?haltestelle=Karl&ubahn=checked&bus=checked&tram=checked&sbahn=checked |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
use Mvg\Parser\Html\Departures; |
|
|
|
|
16
|
|
|
use Mvg\Parser\Html\Stations; |
|
|
|
|
17
|
|
|
use Mvg\TextOutput\Departures as TextOutputDepartures; |
18
|
|
|
use Mvg\TextOutput\Stations as TextOutputStations; |
19
|
|
|
use Mvg\Factories\Departures as DeparturesFactory; |
20
|
|
|
use Mvg\RequestHandler\Html\HttpPostNewsTicker; |
21
|
|
|
use Mvg\RequestHandler\Html\HttpGetDepartures; |
22
|
|
|
use Mvg\TextOutput\NewsTicker as NewsTickerOutput; |
23
|
|
|
|
24
|
|
|
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php'; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
try { |
28
|
|
|
$opts = new Zend\Console\Getopt( |
29
|
|
|
array( |
30
|
|
|
'news|n' => 'Show news about Interferences', |
31
|
|
|
'stations|s=s' => 'Departure Stations - separate multiple stations with ;', |
32
|
|
|
'ends|e=s' => 'end of lines - separate multiple stations with ;' |
33
|
|
|
) |
34
|
|
|
); |
35
|
|
|
$opts->parse(); |
36
|
|
|
|
37
|
|
|
} catch (Zend\Console\Exception\RuntimeException $e) { |
38
|
|
|
echo $e->getUsageMessage(); |
39
|
|
|
exit; |
40
|
|
|
} |
41
|
|
|
if (null === $opts->getOption('s')) { |
42
|
|
|
echo $opts->getUsageMessage(); |
43
|
|
|
exit; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
//Stations |
47
|
|
|
$stationString = trim($opts->getOption('s')); |
|
|
|
|
48
|
|
|
$searchForStations = explode(';', $stationString); |
49
|
|
|
|
50
|
|
|
//End of Lines |
51
|
|
|
if (null !== $opts->getOption('e')) { |
52
|
|
|
$endStationString = trim($opts->getOption('e')); |
|
|
|
|
53
|
|
|
$filterForStations = explode(';', $endStationString); |
54
|
|
|
} else { |
55
|
|
|
$filterForStations = array(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
foreach ($searchForStations as $searchForStation) { |
60
|
|
|
$searchForStation = trim($searchForStation); |
61
|
|
|
$http = new HttpGetDepartures('http', 'www.mvg-live.de', 'ims/dfiStaticAuswahl.svc'); |
|
|
|
|
62
|
|
|
$result = $http->getDeparturesForStation($searchForStation); |
|
|
|
|
63
|
|
|
$parser = new Departures($result); |
|
|
|
|
64
|
|
|
$departures = $parser->getDepartures(); |
|
|
|
|
65
|
|
|
if (0 === count($departures)) { |
66
|
|
|
echo "Station '" . $searchForStation . "' unknown\n"; |
67
|
|
|
echo "Did you mean?\n"; |
68
|
|
|
$stationParser = new Stations($result); |
69
|
|
|
echo (new TextOutputStations($stationParser))->getOutput(); |
70
|
|
|
} else { |
71
|
|
|
$factory = new DeparturesFactory($parser); |
72
|
|
|
echo (new TextOutputDepartures($factory, $filterForStations))->getOutput(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
//Display news from the ticker |
78
|
|
|
if (true === $opts->getOption('n')) { |
79
|
|
|
$responseForNewsTicker = (new HttpPostNewsTicker())->doPostRequest(); |
80
|
|
|
$newsTickerParser = new \ Mvg\Parser\Html\NewsTicker($responseForNewsTicker); |
|
|
|
|
81
|
|
|
$interferences = $newsTickerParser->getInterferences(); |
|
|
|
|
82
|
|
|
if (0 < count($interferences)) { |
83
|
|
|
echo "Interferences\n"; |
84
|
|
|
echo (new NewsTickerOutput($newsTickerParser))->getOutput(); |
85
|
|
|
|
86
|
|
|
} else { |
87
|
|
|
echo "No Interferences\n"; |
88
|
|
|
} |
89
|
|
|
} |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.