From 056efa16f1d297abacf79c1252aeadc0a3394994 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Mon, 19 Oct 2020 20:19:48 +0100 Subject: Make it work --- src/App.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/App.php (limited to 'src/App.php') diff --git a/src/App.php b/src/App.php new file mode 100644 index 0000000..317eb2b --- /dev/null +++ b/src/App.php @@ -0,0 +1,65 @@ +setName('marine'); + + // argument 0 is the command name + $command->addArgument(1); + + $command->setExecuteCallback( + function (InputInterface $input, OutputInterface $output) { + $ship_id = $input->getArgument(1); + + $url = $this->getVesselUrl($ship_id); + + $dom = new Dom; + $dom->loadFromUrl($url); + + $html = $dom->find( + ".column.vfix-top.npr table tbody" + ); + + $out = []; + + foreach ($html as $inner_elem) { + $elem_dom = new Dom(); + $item = $elem_dom->loadStr($inner_elem); + + + $out = ''; + $index = 0; + while ($data = $item->find('tr td', $index)) { + $value = $item->find('tr td', $index+1)->innerHtml(); + $out .= strip_tags($data->innerHtml()) . ': ' . strip_tags($value) . ' '; + + $index += 2; + } + + $output->writeLn(rtrim($out)); + } + + return Command::SUCCESS; + } + ); + + return [$command]; + } + + private function getVesselUrl(string $ship_id): string + { + return "https://www.vesselfinder.com/vessels/" . $ship_id; + } +} -- cgit v1.2.3