Ejemplo n.º 1
0
 public function processContent()
 {
     $body = $this->response->getBody();
     $domDocument = new Query($body);
     $this->content = array();
     foreach ($this->getFields() as $fieldName => $field) {
         if (isset($field['selector'])) {
             foreach ($domDocument->execute($field['selector']) as $result) {
                 if (property_exists($result, $field['getter']) && !isset($field['attr'])) {
                     $this->content[$fieldName][] = $result->{$field}['getter'];
                 }
                 if (method_exists($result, $field['getter']) && isset($field['attr'])) {
                     $this->content[$fieldName][] = $result->{$field['getter']}($field['attr']);
                 }
             }
         }
         if (isset($field['callable']) && method_exists($this, $field['callable'])) {
             $this->{$field}['callable']($fieldName, $domDocument);
         }
         if (isset($field['required']) && !isset($this->content[$fieldName])) {
             throw new ExpectedParamException('Cant get required property ' . $fieldName . ' with ' . $field['selector'] . ' at ' . $this->url);
         }
         if (isset($this->content[$fieldName])) {
             $this->content[$fieldName] = implode(',', str_replace(',', '[comma]', $this->content[$fieldName]));
         } else {
             $this->content[$fieldName] = '';
         }
     }
     var_dump($this->content);
     $this->content['parse_url'] = $this->url;
     CsvFile::putInFile(array($this->content), $this->fileName);
     Logger::addMessage('Successful! Remove from Queue!');
 }
Ejemplo n.º 2
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();
 }