Handle the case where we may receive incorrect data.
This commit is contained in:
parent
61b1aac452
commit
73c1e11e71
1 changed files with 67 additions and 12 deletions
|
@ -23,7 +23,7 @@ define('LOCK',$conf->site->path . '/data/whoisandrew.lock');
|
||||||
// All the sources we intend on pulling data from with a corresponding
|
// All the sources we intend on pulling data from with a corresponding
|
||||||
// cache lifetime.
|
// cache lifetime.
|
||||||
$dataSources = array(
|
$dataSources = array(
|
||||||
'twitter' => 0, //300,
|
'twitter' => 300,
|
||||||
'github' => 300,
|
'github' => 300,
|
||||||
'hulu' => 600,
|
'hulu' => 600,
|
||||||
'lastfm' => 60,
|
'lastfm' => 60,
|
||||||
|
@ -61,8 +61,14 @@ foreach($dataSources as $dataSource=>$refreshTime) {
|
||||||
if(time() - $lastModified > $refreshTime) {
|
if(time() - $lastModified > $refreshTime) {
|
||||||
$cacheData[$dataSource] = time();
|
$cacheData[$dataSource] = time();
|
||||||
|
|
||||||
$sourceData[$dataSource] = call_user_func($dataSource);
|
$sourceData = call_user_func($dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($sourceData != false) {
|
||||||
|
$sourceData[$dataSource] = $sourceData;
|
||||||
|
} else {
|
||||||
|
$cacheData[$dataSource] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents(CACHE,json_encode($cacheData));
|
file_put_contents(CACHE,json_encode($cacheData));
|
||||||
|
@ -79,18 +85,24 @@ function twitter() {
|
||||||
// An empty result set currently (always?) means that the last post was
|
// An empty result set currently (always?) means that the last post was
|
||||||
// retweeted.
|
// retweeted.
|
||||||
if(empty($tweetInfo)) {
|
if(empty($tweetInfo)) {
|
||||||
return array(
|
$data = array(
|
||||||
'text' => 'Last post was a retweet and cannot be listed.',
|
'text' => 'Last post was a retweet and cannot be listed.',
|
||||||
'time' => 0,
|
'time' => 0,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$tweet = urlify($tweetInfo[0]->text);
|
$tweet = urlify($tweetInfo[0]->text);
|
||||||
|
|
||||||
return array(
|
$data = array(
|
||||||
'text' => $tweet,
|
'text' => $tweet,
|
||||||
'time' => strtotime($tweetInfo[0]->created_at),
|
'time' => strtotime($tweetInfo[0]->created_at),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset($data['text']) && isset($data['time'])) {
|
||||||
|
return $data;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function github() {
|
function github() {
|
||||||
|
@ -108,11 +120,17 @@ function github() {
|
||||||
$repos[0]->name);
|
$repos[0]->name);
|
||||||
$commits = json_decode(curl_request($url));
|
$commits = json_decode(curl_request($url));
|
||||||
|
|
||||||
return array(
|
$data = array(
|
||||||
'commit' => $commits[0]->commit->message,
|
'commit' => $commits[0]->commit->message,
|
||||||
'repo' => $repos[0]->name,
|
'repo' => $repos[0]->name,
|
||||||
'url' => $repos[0]->html_url,
|
'url' => $repos[0]->html_url,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(isset($data['commit']) && isset($data['repo']) && isset($data['url'])) {
|
||||||
|
return $data;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function lastfm() {
|
function lastfm() {
|
||||||
|
@ -126,31 +144,43 @@ function lastfm() {
|
||||||
(bool)$latestSong->attributes()->nowplaying) ?
|
(bool)$latestSong->attributes()->nowplaying) ?
|
||||||
0 : strtotime($latestSong->date . ' UTC');
|
0 : strtotime($latestSong->date . ' UTC');
|
||||||
|
|
||||||
return array(
|
$data = array(
|
||||||
'song' => (string)$latestSong->name,
|
'song' => (string)$latestSong->name,
|
||||||
'artist' => (string)$latestSong->artist,
|
'artist' => (string)$latestSong->artist,
|
||||||
'time' => $time,
|
'time' => $time,
|
||||||
'url' => (string)$latestSong->url,
|
'url' => (string)$latestSong->url,
|
||||||
'cover' => $cover,
|
'cover' => $cover,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(isset($data['song']) && isset($data['artist']) && isset($data['time']) && isset($data['url']) && isset($data['cover'])) {
|
||||||
|
return $data;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sc2ranks() {
|
function sc2ranks() {
|
||||||
$url = 'http://sc2ranks.com/api/base/teams/us/Gaffer$888.json?appKey=whoisandrew.com';
|
$url = 'http://sc2ranks.com/api/base/teams/us/Gaffer$888.json?appKey=whoisandrew.com';
|
||||||
$profile = json_decode(file_get_contents($url));
|
$profile = json_decode(file_get_contents($url));
|
||||||
|
|
||||||
// find the 1v1 team
|
// find the 1v1 team
|
||||||
foreach($profile->teams as $team) {
|
foreach($profile->teams as $team) {
|
||||||
if($team->bracket == 1) break;
|
if($team->bracket == 1) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
$data = array(
|
||||||
'league' => $team->league,
|
'league' => $team->league,
|
||||||
'division' => $team->division,
|
'division' => $team->division,
|
||||||
'rank' => $team->division_rank,
|
'rank' => $team->division_rank,
|
||||||
'points' => $team->points,
|
'points' => $team->points,
|
||||||
'wins' => $team->wins,
|
'wins' => $team->wins,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(isset($data['league']) && isset($data['division']) && isset($data['rank']) && isset($data['points']) && isset($data['wins'])) {
|
||||||
|
return $data;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hulu() {
|
function hulu() {
|
||||||
|
@ -164,13 +194,19 @@ function hulu() {
|
||||||
preg_match('/<img src="(.*)" align="right"/',(string)$lastShow->description,
|
preg_match('/<img src="(.*)" align="right"/',(string)$lastShow->description,
|
||||||
$thumb);
|
$thumb);
|
||||||
|
|
||||||
return array(
|
$data = array(
|
||||||
'series' => isset($title[2]) ? $title[0] : 'Not Available',
|
'series' => isset($title[2]) ? $title[0] : 'Not Available',
|
||||||
'title' => isset($title[2]) ? $title[2] : $title[0],
|
'title' => isset($title[2]) ? $title[2] : $title[0],
|
||||||
'time' => strtotime($lastShow->pubDate),
|
'time' => strtotime($lastShow->pubDate),
|
||||||
'url' => (string)$lastShow->link,
|
'url' => (string)$lastShow->link,
|
||||||
'thumb' => $thumb[1],
|
'thumb' => $thumb[1],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(isset($data['series']) && isset($data['title']) && isset($data['time']) && isset($data['url']) && isset($data['thumb'])) {
|
||||||
|
return $data;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function steam() {
|
function steam() {
|
||||||
|
@ -189,10 +225,16 @@ function steam() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
$data = array(
|
||||||
'hours' => (float)$xml->hoursPlayed2Wk,
|
'hours' => (float)$xml->hoursPlayed2Wk,
|
||||||
'recent' => $recentGames,
|
'recent' => $recentGames,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(isset($data['hours']) && isset($data['recent'])) {
|
||||||
|
return $data;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function wow() {
|
function wow() {
|
||||||
|
@ -285,7 +327,20 @@ function wow() {
|
||||||
// required to work in 5.2
|
// required to work in 5.2
|
||||||
usort(&$characterData,'progression_sort');
|
usort(&$characterData,'progression_sort');
|
||||||
|
|
||||||
return $characterData;
|
|
||||||
|
$data = $characterData;
|
||||||
|
|
||||||
|
foreach($data as $character) {
|
||||||
|
if(!isset($character['name'])) return false;
|
||||||
|
if(!isset($character['level'])) return false;
|
||||||
|
if(!isset($character['class'])) return false;
|
||||||
|
if(!isset($character['progression'])) return false;
|
||||||
|
if(!isset($character['armory'])) return false;
|
||||||
|
if(!isset($character['spec_icon'])) return false;
|
||||||
|
if(!isset($character['spec_name'])) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue