summaryrefslogtreecommitdiff
path: root/src/App.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/App.php')
-rw-r--r--src/App.php65
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;
+ }
+}