示例#1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $send = new SendToFacebook('facebook.txt');
     if (!$send->getConectionParameters()) {
         $this->error('Parámetros de conexión incorrectos');
         exit(1);
     }
     $from = $send->getUser();
     $action = ['action' => 'feed', 'from' => $from];
     $result = $send->sendRequest([$action]);
     $db = new SaveFeedsToTable();
     foreach ($result[0] as $feed) {
         // Comprobar si el usuario existe
         if (!$db->verifyIfExists('fb_users', $feed->from->id)) {
             $db->insertData('fb_users', ['id' => $feed->from->id, 'name' => $feed->from->name]);
         }
         // Comprobar si el feed existe
         if (!$db->verifyIfExists('feeds', $feed->id)) {
             $created_at = Carbon::parse($feed->created_time);
             $created_at->setTimezone('America/Bogota');
             if (property_exists($feed, 'message')) {
                 $message = $feed->message;
             } else {
                 $message = NULL;
             }
             if (property_exists($feed, 'story')) {
                 $story = $feed->story;
             } else {
                 $story = NULL;
             }
             $db->insertData('feeds', ['id' => $feed->id, 'created_at' => $created_at->format('Y-m-d H:i:s'), 'message' => $message, 'story' => $story, 'fb_user_id' => $feed->from->id, 'name' => $feed->from->name]);
         }
     }
     $this->info('Actualizacion de feeds correcta');
 }
示例#2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $send = new SendToFacebook('facebook.txt');
     if (!$send->getConectionParameters()) {
         $this->error('Parámetros de conexión incorrectos');
         exit(1);
     }
     $db = new SaveFeedsToTable();
     $request = [];
     $limit = 5;
     $total = $limit * 6;
     for ($i = 1; $i <= $total; $i++) {
         if ($i % $limit == 0) {
             $offset = $i - $limit;
             $feeds_id = $db->getIdOfLastFeeds('feeds', $offset, $limit);
             $action = [];
             foreach ($feeds_id as $id) {
                 $action[] = ['action' => 'comments', 'from' => $id->id];
             }
             $results = $send->sendRequest($action);
             if (count($results) > 0 && is_array($results)) {
                 $count = 0;
                 foreach ($results as $result) {
                     if (count($result) > 0 && is_array($result)) {
                         foreach ($result as $feed) {
                             // Comprobar si el usuario existe
                             if (!$db->verifyIfExists('fb_users', $feed->from->id)) {
                                 $db->insertData('fb_users', ['id' => $feed->from->id, 'name' => $feed->from->name]);
                             }
                             // Comprobar si el feed existe
                             if (!$db->verifyIfExists('feeds', $feed->id)) {
                                 $created_at = Carbon::parse($feed->created_time);
                                 $created_at->setTimezone('America/Bogota');
                                 if (property_exists($feed, 'message')) {
                                     $message = $feed->message;
                                 } else {
                                     $message = NULL;
                                 }
                                 if (property_exists($feed, 'story')) {
                                     $story = $feed->story;
                                 } else {
                                     $story = NULL;
                                 }
                                 $db->insertData('feeds', ['id' => $feed->id, 'created_at' => $created_at->format('Y-m-d H:i:s'), 'message' => $message, 'story' => $story, 'fb_user_id' => $feed->from->id, 'parent_feed_id' => $feeds_id[$count]->id, 'name' => $feed->from->name]);
                             }
                         }
                     }
                     $count++;
                 }
             }
         }
     }
     $this->info('Actualizacion de comentarios correcta');
 }