Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $keyword = $this->argument('keyword');
     $channel = Yt::getChannelByName('allocine');
     if (!empty($channel)) {
         $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
         $collection = new \MongoDB\Collection($manager, 'laravel.stats');
         $collection->deleteMany([]);
         $collection = new \MongoDB\Collection($manager, 'laravel.stats');
         $stat = ['origin' => 'Youtube', 'type' => 'search', 'data' => $channel, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
         $collection->insertOne($stat);
     }
     $params = ['q' => $keyword, 'type' => 'video', 'part' => 'id, snippet', 'maxResults' => 30];
     $videos = Yt::searchAdvanced($params, true)['results'];
     if (!empty($videos)) {
         $collection = new \MongoDB\Collection($manager, 'laravel.videos');
         $collection->deleteMany([]);
         foreach ($videos as $video) {
             $collection = new \MongoDB\Collection($manager, 'laravel.videos');
             $stat = ['data' => $video, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     Log::info("Import de l'API Youtube video done! ");
 }
Пример #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
try {
    $result = $collection->replaceOne(["nick" => "Bobby Fischer"], ["name" => "Magnus Carlsen", "nick" => "unknown", "citizen" => "Norway"]);
    printf("Replaced: %d (out of expected 1), verify Bobby has been replaced with Magnus\n", $result->getModifiedCount());
    $result = $collection->find();
    foreach ($result as $document) {
        var_dump($document);
    }
    echo "\n";
} catch (Exception $e) {
    printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
    exit;
}
try {
    $result = $collection->deleteOne($document);
    printf("Deleted: %d (out of expected 1)\n\n", $result->getDeletedCount());
    $result = $collection->deleteMany(["citizen" => "Iceland"]);
    printf("Deleted: %d (out of expected 2)\n\n", $result->getDeletedCount());
} catch (Exception $e) {
    printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
    exit;
}
try {
    echo "FindOneAndReplace\n";
    $result = $collection->findOneAndReplace($spassky, $kasparov, ["upsert" => true]);
    echo "Kasparov\n";
    var_dump($result);
    echo "\n";
    echo "Returning the old document where he was Russian\n";
    $result = $collection->findOneAndUpdate($kasparov, ['$set' => ["citizen" => "Croatia"]]);
    var_dump($result);
    echo "\n";