$query = "SELECT MAX(date) FROM " . $mysqlDiggsTable; $result = mysql_query($query); $row = mysql_fetch_array($result, MYSQL_NUM); $minDate = $row[0] + 1; // add one second to skip duplicate : doesn't work ... maybe try longer? print "Updating diggs from " . date("Ymd g:i:sa", $minDate) . " ... "; // sort date-asc (oldest first) so if dies in the middle, then won't be missing a middle chunk like date-desc (newest first) $params = array('count' => 100, 'offset' => 0, 'min_date' => $minDate, 'sort' => 'date-asc'); fetch_diggs($diggUser, $mysqlDiggsTable, $params); break; case "fetch-diggs": print "Fetching diggs ..."; //from the beginning //assumed the profile does not edit during the fetch $params = array('count' => 100, 'offset' => 0, 'sort' => 'date-asc'); fetch_diggs($diggUser, $mysqlDiggsTable, $params); break; case "fetch-story-data": //fetch the story data from database //should overwrite //the mysql_fetch_array keeps track of stories fetch so that I don't have to make another variable to do that //get all stories in database //while still stories //if (numstories < 100) fetch numstories; else fetch 100 //get stories and load to array //get story data //for each story //save into database $storyIDs = get_storyIDs($mysqlDiggsTable); $savedStories = fetch_stories($storyIDs, $mysqlStoryTable); print "\n---\nTotal # of stories: " . $numStories . "\nStories saved: " . $savedStories . "\nStories not saved: " . ($numStories - $savedStories) . "\n";
function fetch_diggs() { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://services.digg.com/stories/?type=json&count=10&appkey=http%3A%2F%2Fwrox.com'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'ExampleFacebookApp/0.1'); $body = curl_exec($ch); if (curl_errno($ch)) { return array(); } else { curl_close($ch); $data = json_decode($body); return $data; } } $data = fetch_diggs(); ?> <p>Displaying <?php echo $data->count; ?> articles.</p> <ul> <?php foreach ($data->stories as $story) { ?> <li><a href="<?php echo $story->href; ?> "><?php echo $story->title; ?>