Skip to content
Snippets Groups Projects

IDT v1 Export

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Erick Hitter
    idt_v1_export.php 947 B
    <?php
    $api_key  = '';
    
    $api = 'https://idonethis.com/api/v0.0/dones/';
    
    $page = 1;
    $url = $api;
    
    do {
    	echo "Doing page #{$page}:\n{$url}\n\n";
    	$curl = curl_init();
    
    	curl_setopt_array(
    		$curl, array(
    			CURLOPT_URL            => $url,
    			CURLOPT_RETURNTRANSFER => true,
    			CURLOPT_FOLLOWLOCATION => true,
    			CURLOPT_TIMEOUT        => 10,
    			CURLOPT_ENCODING       => '',
    			CURLOPT_HTTPHEADER     => array(
    				'Content-type:application/json',
    				'Authorization: Token ' . $api_key,
    			),
    		)
    	);
    
    	$_results = curl_exec( $curl );
    
    	if ( curl_error( $curl ) ) {
    		echo "Something failed requesting `{$url}`.\n\n";
    		exit;
    	}
    
    	$results = json_decode( $_results );
    
    	curl_close( $curl );
    
    	$url = $results->next;
    
    	file_put_contents( 'idt_export_page_' . str_pad( $page, 3, 0, STR_PAD_LEFT ) . '.json', $_results );
    
    	++$page;
    
    	$sleep = rand( 1, 3 );
    	echo "Sleeping for {$sleep} seconds...\n\n\n";
    	sleep( $sleep );
    } while ( null != $url );
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment