Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $url = $input->getArgument('urls');
     $fileName = $input->getArgument('file');
     $returnCode = 0;
     // Default retry job
     if ($url) {
         try {
             Logger::addMessage('Running parse: ' . $url);
             $route = $this->registry->router->match($url);
             $route->url = $url;
             $route = $this->processRoute($route);
             $controller = new $route->class(null);
             if (!$input->getOption('compare')) {
                 $this->registry->eventDispatcher->addListener('parse.finished', array(new ParseListener(), 'compare'), 10);
             }
             $this->registry->eventDispatcher->addListener('parse.jobFinished', array(new ParseListener(), 'jobFinish'), 0);
             if (!$input->getOption('mail')) {
                 $this->registry->eventDispatcher->addListener('parse.finished', array(new ParseListener(), 'mail'), 0);
             }
             $controller->{$route->method}($route, $fileName);
             $returnCode = 1;
         } catch (ExpectedParamException $e) {
             Logger::addMessage('Error: ' . $e->getMessage());
             $returnCode = 2;
             // Put into unparsed
         } catch (\Exception $e) {
             Logger::addMessage('Error: ' . $e->getMessage());
         }
     }
     FileLogger::save();
     return $returnCode;
 }
Exemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $limit = $input->getArgument('limit');
     if ($limit > 1) {
         for (; $limit > 0; $limit--) {
             BackgroundProcess::open('php index.php worker:parse 1');
         }
     } else {
         if ($limit == 1) {
             try {
                 $worker = new \Net_Gearman_Worker($this->config->getGearmanHost());
                 $worker->addAbility('parse');
                 $worker->beginWork();
             } catch (\Net_Gearman_Exception $e) {
                 Logger::addMessage($e->getMessage());
                 BackgroundProcess::open('php index.php worker:parse 1');
             }
         }
     }
     FileLogger::save();
 }
Exemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     $dir = $this->config->getParseDir();
     var_dump($dir, $file);
     $fileNew = $dir . $file;
     $baseFileName = basename($file, '.csv');
     $fileOld = $dir . $baseFileName . '_toupdate.csv';
     if (file_exists($fileNew) && file_exists($fileOld)) {
         $dataNew = CsvFile::readFile($fileNew);
         $dataOld = CsvFile::readFile($fileOld);
         $disappearedProducts = array_diff_assoc($dataOld, $dataNew);
         $newProducts = array_diff_assoc($dataNew, $dataOld);
         $reviewsCountChanged = array();
         foreach ($dataNew as $key => $newProd) {
             if (isset($dataOld[$key])) {
                 if (count($newProd['reviews']) != count($dataOld[$key]['reviews'])) {
                     $reviewsCountChanged[] = array('sku' => $newProd['sku'][0], 'count' => count($newProd['reviews']) - count($dataOld[$key]['reviews']));
                 }
             } else {
             }
         }
         $disappearedProducts = array_keys($disappearedProducts);
         $newProducts = array_keys($newProducts);
         array_walk($disappearedProducts, function (&$value) {
             $value = array('sku' => $value);
         });
         array_walk($newProducts, function (&$value) {
             $value = array('sku' => $value);
         });
         var_dump($disappearedProducts);
         var_dump($newProducts);
         CsvFile::putInFile($disappearedProducts, $baseFileName . '_disappeared_products.csv', 'w+');
         CsvFile::putInFile($newProducts, $baseFileName . '_newProducts.csv', 'w+');
         CsvFile::putInFile($reviewsCountChanged, $baseFileName . '_recently_reviewed_products.csv', 'w+');
     }
     FileLogger::save();
 }
Exemplo n.º 4
0
use sys\Logger\FileLogger;
use sys\Logger\Logger;
use sys\Registry;
use sys\Router\Route;
use sys\Router\RouteCollection;
use sys\Router\Router;
use sys\Router\Loader\jsonFileLoader as RouterLoader;
use sys\Config\Loader\jsonFileLoader as ConfigLoader;
$registry = Registry::getInstance();
$configLoader = new ConfigLoader();
$configLoader->setConfigObject(new Config());
$registry->config = $configLoader->load('config/config.json');
$registry->router = new Router();
$registry->eventDispatcher = new EventDispatcher();
$routeLoader = new RouterLoader();
$routeLoader->setRouteCollection(new RouteCollection());
$routeLoader->setRouteClass(new Route());
$registry->router->setRouteCollection($routeLoader->load("config/routes.json"));
try {
    $application = new Application();
    $registry->application = $application;
    $application->add(new Parse());
    $application->add(new Worker());
    $application->add(new Compare());
    $application->run();
} catch (\Exception $e) {
    echo "<pre>";
    echo Logger::toString();
    FileLogger::save();
    echo "</pre>";
}