Ejemplo n.º 1
0
function getProducts()
{
    include "../classes/httpFile.php";
    include "../functions/crawler_functions.php";
    error_reporting(E_ALL ^ E_WARNING);
    $http = new HttpConnection();
    $http->setCookiePath("cookies/");
    $http->init();
    $DOM = new DOMDocument();
    $url_array = split(PHP_EOL, file_get_contents('../file/cats_list.ccd'));
    while (count($url_array) > 0) {
        $url = array_shift($url_array);
        $http->get($url, true);
        get_dom($url, $DOM, $http);
        $finder = new DomXPath($DOM);
        $classname = "product-container";
        $product = $finder->query("//*[contains( normalize-space( @class ), ' {$classname} ' )\r\n\t\t  \t\t\tor substring( normalize-space( @class ), 1, string-length( '{$classname}' ) + 1 ) = '{$classname} '\r\n\t\t  \t\t\tor substring( normalize-space( @class ), string-length( @class ) - string-length( '{$classname}' ) ) = ' {$classname}'\r\n\t\t  \t\t\tor @class = '{$classname}']");
        foreach ($product as $p) {
            $enlaces = $p->getElementsByTagName('a');
            $enlace = $enlaces->item(0)->getAttribute('href');
            echo $enlace . '<br/>';
            file_put_contents("../file/url_list.ccd", $enlace . PHP_EOL, FILE_APPEND);
        }
    }
    $http->close();
}
 /**
  * Returns a transaction from a notification code
  * 
  * @param Credentials $credentials
  * @param String $notificationCode
  * @throws PagSeguroServiceException
  * @throws Exception
  * @return a transaction
  * @see Transaction
  */
 public static function checkTransaction(Credentials $credentials, $notificationCode)
 {
     LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - begin");
     $connectionData = new PagSeguroConnectionData($credentials, self::serviceName);
     try {
         $connection = new HttpConnection();
         $connection->get(self::buildTransactionNotificationUrl($connectionData, $notificationCode), $connectionData->getServiceTimeout(), $connectionData->getCharset());
         $httpStatus = new HttpStatus($connection->getStatus());
         switch ($httpStatus->getType()) {
             case 'OK':
                 // parses the transaction
                 $transaction = TransactionParser::readTransaction($connection->getResponse());
                 LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - end " . $transaction->toString() . ")");
                 break;
             case 'BAD_REQUEST':
                 $errors = TransactionParser::readErrors($connection->getResponse());
                 $e = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
             default:
                 $e = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
         }
         return isset($transaction) ? $transaction : null;
     } catch (PagSeguroServiceException $e) {
         throw $e;
     } catch (Exception $e) {
         LogPagSeguro::error("Exception: " . $e->getMessage());
         throw $e;
     }
 }
Ejemplo n.º 3
0
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$data_twitter = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), true);
foreach ($data_twitter['statuses'] as $statuse) {
    //Formato a fecha
    $date = new DateTime($statuse['created_at']);
    $date->modify('-3 hours');
    $date_format = $date->format('d/m/Y H:i:s');
    //Construcción de array para json
    $data_post[] = array('type' => 'twitter', 'content' => $statuse['text'], 'date' => $date_format, 'likes' => $statuse['favorite_count']);
}
//fin twitter
//Instagram
$http = new HttpConnection();
$http->init();
$data_instagram = json_decode($http->get("https://api.instagram.com/v1/tags/meat/media/recent?access_token=44110995.1677ed0.6d87a7ce19f544c99e2912686465de59&count=25"), true);
$http->close();
foreach ($data_instagram['data'] as $data) {
    //Formato a fecha
    $horas_restantes = 4;
    $date_format = $data['created_time'] - $horas_restantes * 3600;
    $date_format = date('d/m/Y H:i:s', $date_format);
    //Construcción de array para json
    $data_post[] = array('type' => 'instagram', 'content' => $data['images']['standard_resolution']['url'] . ' ' . $data['caption']['text'], 'date' => $date_format, 'likes' => $data['likes']['count']);
}
//fin instagram
//Router
$router = new AltoRouter();
$router->setBasePath('');
$router->map('GET', '/posts', 'posts.php', 'posts');
$router->map('GET', '/posts/likes', 'likes.php', 'likes');
Ejemplo n.º 4
0
} else {
    //Lectura del xml
    echo "<p>Leyendo fichero xml</p>";
    $url_array = leyendo_xml($url_xml);
}
$http = new HttpConnection();
//$http->setCookiePath("cookies/");
$http->init();
/*$registration = array('email'=>'*****@*****.**','passwd'=>"Ayudasmayores",'back'=>"my-account","SubmitLogin"=>"");
	$http->post("http://cosmomedica.com/shop/autenticacion",$registration,true,true);*/
if (isset($user) && isset($pass)) {
    $registration = array('email' => $user, 'passwd' => $pass, 'back' => "my-account", "SubmitLogin" => "");
    $http->post($site_url, $registration, true, true);
    echo "<p>registrandose en la aplicacion</p>";
} else {
    $http->get($site_url, true);
}
$ref_shop = '';
try {
    $DOM = new DOMDocument();
    include $script;
} catch (Exception $e) {
    echo "Procesando url: " . $my_url . "<br />";
    echo "Caught Exception (" . $e->getMessage() . ")\n{$e}\n";
} finally {
    if (count($url_array) > 0) {
        file_put_contents("file/url_list.ccd", "");
        while (count($url_array) > 0) {
            $my_url = array_shift($url_array);
            file_put_contents("file/url_list.ccd", $my_url . PHP_EOL, FILE_APPEND);
        }
 /**
  * Search transactions abandoned associated with this set of credentials within a date range
  *
  * @param Credentials $credentials
  * @param String $initialDate
  * @param String $finalDate
  * @param integer $pageNumber
  * @param integer $maxPageResults
  * @return a object of TransactionSerachResult class
  * @see TransactionSearchResult
  * @throws PagSeguroServiceException
  * @throws Exception
  */
 public static function searchAbandoned(Credentials $credentials, $initialDate, $finalDate, $pageNumber, $maxPageResults)
 {
     LogPagSeguro::info("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin");
     $connectionData = new PagSeguroConnectionData($credentials, self::serviceName);
     $searchParams = array('initialDate' => PagSeguroHelper::formatDate($initialDate), 'finalDate' => PagSeguroHelper::formatDate($finalDate), 'pageNumber' => $pageNumber, 'maxPageResults' => $maxPageResults);
     try {
         $connection = new HttpConnection();
         $connection->get(self::buildSearchUrlAbandoned($connectionData, $searchParams), $connectionData->getServiceTimeout(), $connectionData->getCharset());
         $httpStatus = new HttpStatus($connection->getStatus());
         switch ($httpStatus->getType()) {
             case 'OK':
                 $searchResult = TransactionParser::readSearchResult($connection->getResponse());
                 LogPagSeguro::info("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $searchResult->toString());
                 break;
             case 'BAD_REQUEST':
                 $errors = TransactionParser::readErrors($connection->getResponse());
                 $e = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::error("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $e->getOneLineMessage());
                 throw $e;
                 break;
             default:
                 $e = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::error("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $e->getOneLineMessage());
                 throw $e;
                 break;
         }
         return isset($searchResult) ? $searchResult : false;
     } catch (PagSeguroServiceException $e) {
         throw $e;
     } catch (Exception $e) {
         LogPagSeguro::error("Exception: " . $e->getMessage());
         throw $e;
     }
 }
Ejemplo n.º 6
0
 /**
  * Perform this action
  *
  * @param   string[] args
  */
 public function perform(array $args)
 {
     $installation = new Installation();
     $installation->setBase(new Folder(isset($args[0]) ? $args[0] : dirname(Runtime::getInstance()->bootstrapScript()) . '/..'));
     $force = in_array('-f', $args);
     with($version = $installation->getVersion());
     Console::writeLine('===> Local version ', $version, ' @ ', $installation->getBase());
     if (strstr($version, '-dev')) {
         Console::writeLine('*** Cannot update development checkouts');
         return 2;
     }
     // Query releases website for newer versions
     $c = new HttpConnection(self::UPGRADE_URL);
     $r = $c->get(new RequestData($version));
     switch ($r->getStatusCode()) {
         case HttpConstants::STATUS_OK:
         case HttpConstants::STATUS_NOT_EXTENDED:
             Console::writeLine('*** ', $this->readLine($r->getInputStream()));
             return 2;
         case HttpConstants::STATUS_SEE_OTHER:
             $upgrade = $r->getHeader('X-Upgrade-To');
             $base = $r->getHeader('Location');
             Console::writeLine('---> Upgrading to ', $upgrade, ' (', $base, ')');
             $target = new Folder($installation->getBase(), $upgrade);
             $target->exists() || $target->create();
             // Verify dependencies
             $this->extract($base, 'depend', $target);
             with($p = new Properties($target->getURI() . 'depend.ini'));
             $verify = 1;
             $rtversion = phpversion();
             $extensions = array_flip(array_map('strtolower', get_loaded_extensions()));
             foreach ($p->readSection('php') as $op => $compare) {
                 if (!version_compare(phpversion(), $compare, $op)) {
                     $verify &= $this->error('PHP version ' . $op . ' ' . $compare . ' required, have ' . $rtversion);
                 }
             }
             foreach ($p->readSection('ext.required') as $ext => $usage) {
                 if (!isset($extensions[$ext])) {
                     $verify &= $this->error('PHP Extension ' . $ext . ' required for ' . $usage);
                 }
             }
             foreach ($p->readSection('ext.conflict') as $ext => $usage) {
                 if (isset($extensions[$ext])) {
                     $verify &= $this->error('PHP Extension ' . $ext . ' conflicts (' . $usage . ')');
                 }
             }
             foreach ($p->readSection('ext.optional') as $ext => $usage) {
                 if (!isset($extensions[$ext])) {
                     $verify &= $this->error('PHP Extension ' . $ext . ' not found, needed for ' . $usage . ' (ignoring)');
                 }
             }
             foreach ($p->readSection('ini') as $setting => $match) {
                 $value = ini_get($setting);
                 if (!preg_match($match, $value)) {
                     $verify &= $this->error('PHP .ini setting ' . $setting . ' needs to match ' . $match . ' (but is ' . $value . ')');
                 }
             }
             // Remove depend.ini, finally check if we should continue
             create(new File($p->getFilename()))->unlink();
             if (!$verify) {
                 if (!$force) {
                     return 3;
                 }
                 Console::writeLine('!!! Ignoring errors because -f was passed');
             }
             // Download base, tools, libraries and meta information
             $this->extract($base, 'base', $target);
             $this->extract($base, 'tools', $target);
             $this->extract($base, 'lib', $target);
             $this->extract($base, 'meta-inf', $target);
             // Verify it works by running the XP Framework core unittests
             $tests = array('net.xp_framework.unittest.core.**');
             Console::writeLine('---> Running tests with [USE_XP=', $upgrade, ']:');
             $rt = Runtime::getInstance();
             set_include_path(implode(PATH_SEPARATOR, array(rtrim($target->getURI(), DIRECTORY_SEPARATOR), '', $target->getURI() . 'lib' . DIRECTORY_SEPARATOR . 'xp-net.xp_framework-' . $upgrade . '.xar')));
             with($p = $rt->newInstance($rt->startupOptions(), 'class', 'xp.unittest.Runner', $tests));
             $p->in->close();
             while (!$p->out->eof()) {
                 Console::writeLine($p->out->readLine());
             }
             while (!$p->err->eof()) {
                 Console::writeLine($p->err->readLine());
             }
             $exit = $p->close();
             // Nonzero exit means failure
             if (0 !== $exit) {
                 Console::writeLine('*** Test run failed, please consult above error messsages');
                 Console::writeLine($p->getCommandLine());
                 return 2;
             }
             Console::writeLine('===> Done, installed @ ', $target);
             return 0;
         default:
             throw new IllegalStateException('Unexpected response ' . xp::stringOf($r));
     }
 }
Ejemplo n.º 7
0
<?php 
header('Content-Type: text/html; charset=utf-8');
//error_reporting(E_ALL ^ E_WARNING);
include "../classes/httpFile.php";
//include("classes/product.php");
include "../functions/crawler_functions.php";
$url = $_POST['url'];
$script = $_POST['script'];
echo $url . '   ' . $script;
$http = new HttpConnection();
//$http->setCookiePath("cookies/");
$http->init();
/*$registration = array('email'=>'*****@*****.**','passwd'=>"Ayudasmayores",'back'=>"my-account","SubmitLogin"=>"");
	$http->post("http://cosmomedica.com/shop/autenticacion",$registration,true,true);*/
$http->get($url, true);
echo "<p>registrandose en la aplicacion</p>";
$DOM = new DOMDocument();
get_dom($url, $DOM, $http);
$count_success = 0;
include "../mainscripts/cat/" . $script;
getCats($DOM);
//echo "<br />";
//opcciones finales
$http->close();
echo "<p>Se han procesado {$count_success} urls correctamente</p>";
echo "<a href='getProducts.php?parser=" . $script . "' class='btn-type'>Obtener Productos</a>";
/*	$configuracion['variables']['ref_count'] = $reference_count;
	$achivo_contenido = ";<?php die(); ?>".PHP_EOL.put_ini_file(null,$configuracion);
	file_put_contents('crawler.conf.php', $achivo_contenido);

	echo "<p>Se han procesado $count_success urls correctamente</p>";