function getFixture($game, $url) { $filename = FIXTURES_DIR . '/' . urlToFilename($game, $url); if (file_exists($filename) === false) { return null; } return file_get_contents('compress.zlib://' . $filename); }
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 "[0m[[31m" . $exception->getCode() . "[0m][" . md5($filename) . '] ' . $filename . PHP_EOL; } } while ($success === false); } else { print "[0m[[33m304[0m][" . md5($filename) . '] ' . $filename . PHP_EOL; } return json_decode($this->getFixture($filename)['content'], true); }
#!/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' ) ) {