Skip to content

Instantly share code, notes, and snippets.

@florentsorel
Created December 22, 2015 20:46
Show Gist options
  • Save florentsorel/e366823a947bbcb1e1fc to your computer and use it in GitHub Desktop.
Save florentsorel/e366823a947bbcb1e1fc to your computer and use it in GitHub Desktop.
<?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