Skip to content

Instantly share code, notes, and snippets.

@ljanecek
Created March 21, 2018 10:25
Show Gist options
  • Select an option

  • Save ljanecek/2a471ea00117e4b23a06aa9cc5a7c190 to your computer and use it in GitHub Desktop.

Select an option

Save ljanecek/2a471ea00117e4b23a06aa9cc5a7c190 to your computer and use it in GitHub Desktop.
$file = __DIR__ . '/../data/twitter.json';
$tweets = array();
if(!file_exists($file) || (file_exists($file) && time()-filemtime($file) >= 3600)){
try {
$data = self::get_twitter_data();
} catch (Exception $e) {
$data = array();
}
if (!empty($data) && empty($data->errors)) {
file_put_contents($file, json_encode($data));
$current = $data;
}else{
$current = json_decode(file_get_contents($file));
}
}else{
$current = json_decode(file_get_contents($file));
}
foreach ($current as $key => $tweet) {
$tweets[] = array(
'data' => $text,
'retweet_count' => $tweet->retweet_count,
'favorite_count' => $tweet->favorite_count,
'created_at' => $tweet->created_at
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment