protected function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); $em = $container->get('doctrine')->getManager(); //$utils = $container->get('sbranch.common.utils'); $items = $em->getRepository("AppBundle:Item")->findTimed(); $output->writeln('Total count items ' . sizeof($items)); $progress = new ProgressBar($output, sizeof($items)); $progress->start(); foreach ($items as $item) { $progress->advance(); // if($item->getHtmlDocument()) { // $document = new Document(); // $document->loadHtml($item->getHtmlDocument()); // } else { // // } $document = new Document($item->getUrl(), true); $title = $document->find('title'); //TODO: this parsing is shitcode $piecesTitle = explode(":", $title[0]->text()); $piecesTitle2 = explode('-', trim(end($piecesTitle))); $priceString = trim($piecesTitle2[0]); $pricePieces = explode(' ', $priceString); $currency = trim(end($pricePieces)); $price = trim(str_replace($currency, '', $priceString)); $price = trim(str_replace(' ', '', $price)); $title = $piecesTitle[0]; $item->setTitle($title); if ($price != $item->getPrice()) { $item->setPriceOld($item->getPrice()); } $item->setPrice($price); $item->setCurrency($currency); $item->setLastCheck(new \DateTime()); $item->setHtmlDocument($document->html()); $em->persist($item); } $progress->finish(); $em->flush(); $output->writeln('Ok'); }
public function testHtml() { $html = $this->loadFixture('posts.html'); $document = new Document($html, false); $this->assertTrue(is_string($document->html())); }
public function testToString() { $html = $this->loadFixture('posts.html'); $document = new Document($html, false); $this->assertEquals($document->html(), $document->__toString()); }