Created
March 21, 2018 10:25
-
-
Save ljanecek/2a471ea00117e4b23a06aa9cc5a7c190 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| $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