Created
September 14, 2016 19:56
-
-
Save davidsword/af54a40674b53c37b84e364adc29c3cc to your computer and use it in GitHub Desktop.
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
<? | |
$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."&v=2&shelf=currently-reading&sort=date_started&order=d&page=1&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."&v=2&shelf=read&sort=date_started&order=d&page=1&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