public function handle()
 {
     $request_token = ['token' => $this->userTwitterToken->short_lived_token, 'secret' => $this->userTwitterToken->long_lived_token];
     // $twitter = App::make('Thujohn\Twitter\Twitter');
     $twitter = Twitter::reconfig($request_token);
     $twitterSincePaginatorData = new GetTwitterSinceIdForPagination($this->userTwitterToken->user_id);
     $twitterSinceId = $twitterSincePaginatorData->retrieve();
     $firstCall = $twitterSinceId === 0 ? true : false;
     do {
         $twitterSincePaginatorData = new GetTwitterSinceIdForPagination($this->userTwitterToken->user_id);
         $twitterSinceId = $twitterSincePaginatorData->retrieve();
         $twitterCallParams = array('id' => $this->userTwitterToken->entity_id, 'count' => 100, 'format' => 'json');
         if ($twitterSinceId > 0) {
             $twitterCallParams['since_id'] = $twitterSinceId;
         }
         $checkIfSocialMediaTokenHasFilters = new CheckIfSocialMediaTokenHasFilters($this->userTwitterToken);
         $filter = $checkIfSocialMediaTokenHasFilters->get();
         $tweets = json_decode(Twitter::getUserTimeline($twitterCallParams));
         foreach ($tweets as $tweet) {
             $assignToDB = false;
             if ($filter) {
                 $checkIfTweetHasFilter = new CheckIfTweetHasFilter($tweet->entities->hashtags, $filter->filter);
                 if ($checkIfTweetHasFilter->check()) {
                     $assignToDB = true;
                 }
             } else {
                 $assignToDB = true;
             }
             if ($assignToDB) {
                 $assignTweetsToDb = new AssignTweetsToDatabase($this->userTwitterToken->user_id, $tweet);
                 $assignTweetsToDb->assign();
             }
         }
         $twitterPaginatorData = new GetTwitterMaxIdForPagination($tweets);
         $twitterMaxId = $twitterPaginatorData->extract();
     } while (!$firstCall && count($tweets) > 0);
 }
Пример #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $infos = \Thujohn\Twitter\Facades\Twitter::getUsersLookup(['screen_name' => 'Symfomany', 'format' => 'php']);
     $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
     $collection = new \MongoDB\Collection($manager, 'laravel.tweets');
     if (!empty($infos)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'infos']);
         $stat = ['origin' => 'Twitter', 'type' => 'infos', 'data' => $infos, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
         $collection->insertOne($stat);
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getDmsOut(['format' => 'php']);
     if (!empty($tweets)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'dmsout']);
         foreach ($tweets as $tweet) {
             $stat = ['origin' => 'Twitter', 'type' => 'dmsout', 'data' => $tweet, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getFavorites(['format' => 'php']);
     if (!empty($tweets)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'favorites']);
         foreach ($tweets as $tweet) {
             $stat = ['origin' => 'Twitter', 'type' => 'favorites', 'data' => $tweet, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getMentionsTimeline(['count' => 15, 'format' => 'php']);
     if (!empty($tweets)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'mentionstimeline']);
         foreach ($tweets as $tweet) {
             $stat = ['origin' => 'Twitter', 'type' => 'mentionstimeline', 'data' => $tweet, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getHomeTimeline(['count' => 15, 'format' => 'php']);
     if (!empty($tweets)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'hometimeline']);
         foreach ($tweets as $tweet) {
             $stat = ['origin' => 'Twitter', 'type' => 'hometimeline', 'data' => $tweet, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getUserTimeline(['screen_name' => 'allocine', 'count' => 15, 'format' => 'php']);
     if (!empty($tweets)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'usertimeline']);
         foreach ($tweets as $tweet) {
             $stat = ['origin' => 'Twitter', 'type' => 'usertimeline', 'data' => $tweet, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
 }
Пример #3
0
 public function sendRequest($username)
 {
     $user = $username;
     $cacheTag = 'twitterTimeline';
     //config timeline twitter
     $cacheKey = $user . "-" . $cacheTag;
     $cacheLimit = 15;
     $tweets = null;
     /* caching */
     if (Cache::has($cacheKey)) {
         $tweets = Cache::get($cacheKey);
     } else {
         $tweets = Twitter::getUserTimeline(['screen_name' => $user, 'count' => 10, 'format' => 'object']);
         Cache::put($cacheKey, $tweets, $cacheLimit);
     }
     return $tweets;
 }
Пример #4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $infos = \Thujohn\Twitter\Facades\Twitter::getUsersLookup(['screen_name' => 'Symfomany', 'format' => 'php']);
     if (!empty($infos)) {
         DB::connection('mongodb')->collection('stats')->where(['origin' => 'Twitter', 'type' => 'infos'])->delete();
         $stat = new Stats();
         $stat->origin = "Twitter";
         $stat->type = "infos";
         $stat->data = $infos;
         $stat->save();
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getDmsOut(['format' => 'php']);
     if (!empty($tweets)) {
         DB::connection('mongodb')->collection('tweets')->where(['origin' => 'Twitter', 'type' => 'dmsout'])->delete();
         foreach ($tweets as $tweet) {
             $vi = new Tweets();
             $vi->origin = "Twitter";
             $vi->type = "dmsout";
             $vi->data = $tweet;
             $vi->save();
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getFavorites(['format' => 'php']);
     if (!empty($tweets)) {
         DB::connection('mongodb')->collection('tweets')->where(['origin' => 'Twitter', 'type' => 'favorites'])->delete();
         foreach ($tweets as $tweet) {
             $vi = new Tweets();
             $vi->origin = "Twitter";
             $vi->type = "favorites";
             $vi->data = $tweet;
             $vi->save();
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getMentionsTimeline(['count' => 15, 'format' => 'php']);
     if (!empty($tweets)) {
         DB::connection('mongodb')->collection('tweets')->where(['origin' => 'Twitter', 'type' => 'mentionstimeline'])->delete();
         foreach ($tweets as $tweet) {
             $vi = new Tweets();
             $vi->origin = "Twitter";
             $vi->type = "mentionstimeline";
             $vi->data = $tweet;
             $vi->save();
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getHomeTimeline(['count' => 15, 'format' => 'php']);
     if (!empty($tweets)) {
         DB::connection('mongodb')->collection('tweets')->where(['origin' => 'Twitter', 'type' => 'hometimeline'])->delete();
         foreach ($tweets as $tweet) {
             $vi = new Tweets();
             $vi->data = $tweet;
             $vi->origin = "Twitter";
             $vi->type = "hometimeline";
             $vi->save();
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getUserTimeline(['screen_name' => 'allocine', 'count' => 15, 'format' => 'php']);
     if (!empty($tweets)) {
         DB::connection('mongodb')->collection('tweets')->where(['origin' => 'Twitter', 'type' => 'usertimeline'])->delete();
         foreach ($tweets as $tweet) {
             $vi = new Tweets();
             $vi->data = $tweet;
             $vi->origin = "Twitter";
             $vi->type = "usertimeline";
             $vi->save();
         }
     }
 }
Пример #5
-1
 protected function getTwitterFeed($feedname)
 {
     if (!Cache::has($feedname)) {
         if (strpos($feedname, 'Home')) {
             $timeline = Twitter::getHomeTimeline(array('screen_name' => Config::get('feeds.twitterScreenName'), 'count' => 3, 'format' => 'object'));
         } else {
             $timeline = Twitter::getUserTimeline(array('screen_name' => Config::get('feeds.twitterScreenName'), 'count' => 3, 'format' => 'object'));
         }
         Cache::add($feedname, $timeline, 60);
     }
     return Cache::get($feedname);
 }