diff options
author | Fbenas <philbeansburton@gmail.com> | 2020-10-19 20:19:48 +0100 |
---|---|---|
committer | Fbenas <philbeansburton@gmail.com> | 2020-10-19 20:19:48 +0100 |
commit | 056efa16f1d297abacf79c1252aeadc0a3394994 (patch) | |
tree | 78c6eceb3339ee3a9cc4b74b83fd4fb01a5a14f1 /src | |
parent | b122bc54dd2bcc8c2c39d79247661770d36d8073 (diff) |
Diffstat (limited to 'src')
-rw-r--r-- | src/App.php | 65 |
1 files changed, 65 insertions, 0 deletions
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 @@ +<?php + +namespace FBeans\Blamarine; + +use FBeans\BlaIRC\Command; +use FBeans\BlaIRC\Application As BlaApplication; +use PHPHtmlParser\Dom; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + + +class App extends BlaApplication +{ + public function commands(): Array + { + $command = new Command; + $command->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; + } +} |