90 lines
1.6 KiB
PHP
90 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use LaravelZero\Framework\Commands\Command;
|
|
use Log;
|
|
|
|
class Collect extends Command
|
|
{
|
|
/**
|
|
* The signature of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'collect {keyword?}';
|
|
|
|
/**
|
|
* The description of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Collect info about new games';
|
|
|
|
/**
|
|
* List of parsers to run.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $parsers = [
|
|
'Anivisual',
|
|
'Hyperbook',
|
|
'HyperbookEn',
|
|
'Apero',
|
|
'Questbook',
|
|
'Axma',
|
|
'IFDB',
|
|
'Itch',
|
|
'Instead',
|
|
'Steam',
|
|
'Kvester',
|
|
'Urq',
|
|
'Instory',
|
|
'Ifiction',
|
|
'Gamejolt',
|
|
'Textadventures',
|
|
'Dashingdon',
|
|
// 'VNDB',
|
|
];
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
Log::debug('Collecting.');
|
|
$keyword = $this->argument('keyword');
|
|
foreach ($this->parsers as $parser) {
|
|
$cname = 'App\\Sources\\'.$parser;
|
|
try {
|
|
$instance = new $cname();
|
|
if (!empty($keyword) && !isset($instance->keyword)) {
|
|
continue;
|
|
}
|
|
if (!empty($keyword) && $instance->keyword !== $keyword) {
|
|
continue;
|
|
}
|
|
Log::debug($parser);
|
|
$instance->parse();
|
|
} catch (\Exception $e) {
|
|
Log::error($e->getMessage());
|
|
Log::debug($e->getTraceAsString());
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Define the command's schedule.
|
|
*
|
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
|
* @return void
|
|
*/
|
|
public function schedule(Schedule $schedule): void
|
|
{
|
|
$schedule->command(static::class)->daily();
|
|
}
|
|
}
|