Esempio n. 1
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);
         }
     }
 }
Esempio n. 2
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();
         }
     }
 }