Last active
July 20, 2022 15:25
-
-
Save Hero-Development/21d951957c891dff0242f53f3def3a36 to your computer and use it in GitHub Desktop.
Automated script to refresh your OpenSea Collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting( E_ALL ); | |
ini_set( 'display_errors', 1 ); | |
$API_KEY = 'xxxxxxxxxxxxxxxx'; | |
$COLLECTION = '0xacfa101ece167f1894150e090d9471aee2dd3041'; | |
$ch = curl_init(); | |
$fd = tmpfile(); | |
for( $i = 0; $i < 7777; $i ){ | |
$url = "https://api.opensea.io/api/v1/asset/{$COLLECTION}/{$i}/?force_update=true"; | |
$options = array( | |
//CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_FILE => $fd, | |
CURLOPT_HEADER => true, | |
CURLOPT_NOBODY => true, | |
CURLOPT_SSL_VERIFYPEER => false, | |
CURLOPT_TIMEOUT => 10, | |
CURLOPT_HTTPGET => true, | |
CURLOPT_HTTPHEADER => array( | |
"X-API-KEY: {$API_KEY}" | |
), | |
CURLOPT_URL => $url | |
); | |
curl_setopt_array($ch, $options); | |
curl_setopt($ch, CURLOPT_HTTPGET, true); | |
$res = curl_exec($ch); | |
$errno = curl_errno($ch); | |
$info = curl_getinfo($ch); | |
fseek( $fd, 0 ); | |
$line1 = trim( fgets( $fd ) ); | |
ftruncate( $fd, 0 ); | |
if( $errno ){ | |
echo date( 'H:i:s' ) ." FAIL( {$i} ): {$errno}: ". curl_error( $ch ) . PHP_EOL; | |
sleep( 1 ); //1 second backoff | |
} | |
else if( $info['http_code'] === 200 ){ | |
++$i; | |
echo date( 'H:i:s' ) ." PASS( {$i} ): {$line1} / {$info['download_content_length']} bytes / {$info['total_time']} seconds" . PHP_EOL; | |
usleep( 250000 ); //1/4 second, API key rate limit | |
} | |
else{ | |
echo date( 'H:i:s' ) ." FAIL( {$i} ): {$info['http_code']}" . PHP_EOL; | |
sleep( 1 ); //1 second backoff | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment