Skip to content

Instantly share code, notes, and snippets.

@davidsword
Created September 14, 2016 19:56
Show Gist options
  • Save davidsword/af54a40674b53c37b84e364adc29c3cc to your computer and use it in GitHub Desktop.
Save davidsword/af54a40674b53c37b84e364adc29c3cc to your computer and use it in GitHub Desktop.
<?
$curl_options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER =>; false,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_ENCODING => "",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 8,
CURLOPT_TIMEOUT => 8,
CURLOPT_MAXREDIRS => 3,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13"
);
// Is the file older than $refreshbook, or the file is new/empty?
if ($force_refresh || ((time() - filectime($cache)) > ($refreshbook * 3600) || 0 == filesize($cache))) {
// the query, pretty straight forward
$reading_books_path = "https://www.goodreads.com/review/list/".$user.".xml?key=".$apikey."&amp;v=2&amp;shelf=currently-reading&amp;sort=date_started&amp;order=d&amp;page=1&amp;per_page=2";
// make the curl request, basically get_file_contents().
$ch = curl_init($reading_books_path);
curl_setopt_array($ch, $curl_options);
$content = curl_exec( $ch );
if(curl_error($ch)) output('Curl error:' . curl_error($ch) . "<br />");
curl_close( $ch );
# again, but for read
sleep(2);//1 query per second for goodreads api
$reading_books_path = "https://www.goodreads.com/review/list/".$user.".xml?key=".$apikey."&amp;v=2&amp;shelf=read&amp;sort=date_started&amp;order=d&amp;page=1&amp;per_page=5";
$ch = curl_init($reading_books_path);
curl_setopt_array($ch, $curl_options);
$content_read = curl_exec( $ch );
if(curl_error($ch)) output('Curl error:' . curl_error($ch) . "<br />");
curl_close( $ch );
// save curl request results to cache, store together, but serperate two
$handle = fopen($cache, 'wb');
fwrite($handle, $content.$breaker.$content_read);
fclose($handle);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment