Created
December 22, 2015 20:46
-
-
Save florentsorel/e366823a947bbcb1e1fc to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Tmdb\Repository\DiscoverRepository; | |
use Tmdb\Model\Query\Discover\DiscoverTvQuery; | |
class Series extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'tmdb:series'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Save tv shows in the database'; | |
protected $repository; | |
/** | |
* Create a new command instance. | |
* | |
* @param DiscoverRepository $repository | |
*/ | |
public function __construct(DiscoverRepository $repository) | |
{ | |
parent::__construct(); | |
$this->repository = $repository; | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$query = new DiscoverTvQuery(); | |
$query->page(1); | |
$this->loop($query, 1); | |
} | |
private function loop(DiscoverTvQuery $query, $start) | |
{ | |
$num = 0; | |
$currentPage = $start == 1 ? $start : $start + 1; | |
do | |
{ | |
$data = $this->repository->discoverTv($query); | |
foreach($data as $d) | |
{ | |
$this->info($d->getOriginalName()); | |
} | |
$query->page($currentPage); | |
$currentPage++; | |
$num += 20; | |
} | |
while($num <= 1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment