示例#1
0
 function getFixture($game, $url)
 {
     $filename = FIXTURES_DIR . '/' . urlToFilename($game, $url);
     if (file_exists($filename) === false) {
         return null;
     }
     return file_get_contents('compress.zlib://' . $filename);
 }
示例#2
0
 public function get($url, array $options = [])
 {
     $query = array_key_exists('query', $options) === false ? '' : implode('&', $options['query']);
     $url = $url . '?' . $query;
     $filename = urlToFilename($this->game, $url);
     $fixture = $this->getFixture($filename);
     $success = false;
     if (strtotime($fixture['modified']) < strtotime('-1 day')) {
         do {
             try {
                 $response = $this->client->get($this->game . '/' . $url, array_replace_recursive($options, ['headers' => ['If-Modified-Since' => $fixture['modified'], 'Accept' => 'application/json', 'User-Agent' => 'pwnRaid/' . static::VERSION], 'query' => ['apikey' => $this->apiKey, 'locale' => $this->region->getLocale()]]));
                 $this->saveFixture($filename, $response);
                 $success = true;
             } catch (BadResponseException $exception) {
                 print "[" . $exception->getCode() . "][" . md5($filename) . '] ' . $filename . PHP_EOL;
             }
         } while ($success === false);
     } else {
         print "[304][" . md5($filename) . '] ' . $filename . PHP_EOL;
     }
     return json_decode($this->getFixture($filename)['content'], true);
 }
示例#3
0
#!/usr/bin/env php
<?

require_once 'ezc/Base/ezc_bootstrap.php';

$urls = explode( "\n", stream_get_contents( STDIN ) );
shuffle( $urls );

$destinationDir = dirname( __FILE__ ).'/../tests/data_robots_txt/';

foreach( $urls as $url )
{
    $filename = $destinationDir.urlToFilename( $url );
    if( file_exists( $filename ) )
    {
        continue;
    }

    echo $url,"\n";
    $txt = loadRobotsTxt( $url );
    if( $txt )
    {
        file_put_contents( $filename, $txt );
    }
}

function loadRobotsTxt( $url )
{
    $txt = @file_get_contents( 'http://'.$url.'/robots.txt' );
    if( FALSE !== stripos( $txt, '<html' ) )
    {