/**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL) {
         $dispatcher = $this->factory->getEventDispatcher();
         $dispatcher->addSubscriber(new ScrapeOutputSubscriber($output));
     }
     $scrapers = $this->findScrapers($input->getArgument('scraper'));
     foreach ($scrapers as $scraperEntity) {
         $url = $scraperEntity->getUrl();
         $output->writeln(sprintf('Found scraper: <info>%s</info>', $url));
         $output->writeln(sprintf('- Start every <info>%s</info> hours', $scraperEntity->getStartFrequency()));
         if ($date = $scraperEntity->getDatetimeLastStarted()) {
             $output->writeln(sprintf('- Last started at <info>%s</info>', $date->format(DATE_RFC2822)));
             $nextStart = $date->add(new \DateInterval(sprintf('PT%sH', $scraperEntity->getStartFrequency())));
             if ($nextStart > new \DateTime()) {
                 $output->writeln(sprintf('- Next start time at <info>%s</info>', $nextStart->format(DATE_RFC2822)));
                 continue;
             }
         } else {
             $output->writeln('- Scraper has <info>never</info> started');
         }
         $output->writeln('Starting scraper...');
         $output->writeln('-------------------');
         try {
             $this->scrape($input, $scraperEntity);
         } catch (CrawlException $e) {
             $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
         }
         $output->writeln('-------------------');
         $output->writeln('');
     }
 }
 public function testConstructWithDispatcher()
 {
     $dispatcher = new EventDispatcher();
     $factory = new ScraperFactory($dispatcher);
     $this->assertSame($dispatcher, $factory->getEventDispatcher());
 }