diff --git a/app/Console/Commands/Grap.php b/app/Console/Commands/Grap.php index 3dba584a..62611355 100644 --- a/app/Console/Commands/Grap.php +++ b/app/Console/Commands/Grap.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use App\Console\Commands\Grapper\Sofascore\Grapper; use App\Console\Commands\Grapper\Sofascore\GrapperTest; use App\Console\Commands\Grapper\Sofascore\Helper\ClearDir; +use App\Console\Commands\Grapper\Sofascore\Helper\RemoveDir; use App\Console\Commands\Grapper\Sofascore\Helper\SetStorage; use App\Console\Commands\Grapper\Sofascore\MakeExcel; use App\Console\Commands\Grapper\Sofascore\Rose; @@ -28,7 +29,7 @@ class Grap extends Command public static string $useragent = '4'; - protected $signature = 'grp {id=0} {day=0} {--date=} {--folder=} {--d} {--r} {--m} {--f} {--R} {--S}'; + protected $signature = 'grp {id=0} {day=0} {--date=} {--folder=} {--d} {--g} {--r} {--c} {--m} {--f} {--F} {--R} {--S}'; public function handle() { @@ -41,8 +42,11 @@ class Grap extends Command $txt = 'PARAMETERS' . PHP_EOL; $txt .= '--d debug' . PHP_EOL; $txt .= '--r restart range' . PHP_EOL; - $txt .= '--f force' . PHP_EOL; + $txt .= '--f force Events' . PHP_EOL; + $txt .= '--F force DayTournament links' . PHP_EOL; + $txt .= '--c clear grap dir' . PHP_EOL; $txt .= '--m mail only' . PHP_EOL; + $txt .= '--g grap & excel only' . PHP_EOL; $txt .= '--R read file' . PHP_EOL; $txt .= '--S save to file' . PHP_EOL; $txt .= '--folder' . PHP_EOL; @@ -66,7 +70,8 @@ class Grap extends Command case 1: // DAILY SetStorage::set(1); - // MoveToArchive::move(1); + + RemoveDir::remove(); // with --m just resend mail if (! self::$options['m']) { @@ -74,21 +79,31 @@ class Grap extends Command MakeExcel::create(); } - SendMail::run(1); + // with --g just grap & excel + if (! self::$options['g']) { + SendMail::run(1); + } break; case 2: // LAST 3 DAYS - SetStorage::set(2); + self::$options['f'] = 1; - ClearDir::clear(); + if (self::$options['c']) { + ClearDir::clear(); + } - Grapper::load(2); + self::$options['day'] = 1; + SetStorage::set(1); + Grapper::load(1); + MakeExcel::create('day'); - MakeExcel::create(); + self::$options['day'] = 5; + SetStorage::set(1); + Grapper::load(1); + MakeExcel::create('day'); SendMail::run(1); - break; case 3: // RANGE diff --git a/app/Console/Commands/Grapper/Sofascore/DaysTournament.php b/app/Console/Commands/Grapper/Sofascore/DaysTournament.php index 04aaed2c..7db0cbfc 100644 --- a/app/Console/Commands/Grapper/Sofascore/DaysTournament.php +++ b/app/Console/Commands/Grapper/Sofascore/DaysTournament.php @@ -26,7 +26,7 @@ class DaysTournament public static function get(string $day) { $debug = Grap::$options['d'] ?? 0; - $force = Grap::$options['f'] ?? 0; + $force = Grap::$options['F'] ?? 0; $tournaments_counter = 0; diff --git a/app/Console/Commands/Grapper/Sofascore/Helper/ClearDir.php b/app/Console/Commands/Grapper/Sofascore/Helper/ClearDir.php index f2259d14..e8196943 100644 --- a/app/Console/Commands/Grapper/Sofascore/Helper/ClearDir.php +++ b/app/Console/Commands/Grapper/Sofascore/Helper/ClearDir.php @@ -8,16 +8,21 @@ use Illuminate\Filesystem\Filesystem; class ClearDir { - public static function clear(): void + public static function clear($dir = ''): void { + $file = new Filesystem; $debug = Grap::$options['d']; - $file = new Filesystem; - - $file->cleanDirectory(Grap::$storage); - - if ($debug) { - Notice::note('Directory: ' . Grap::$storage . ' - All content cleard', 'p'); + if ($dir) { + $file->cleanDirectory($dir); + if ($debug) { + Notice::note('Dir: ' . $dir . ' - removed', 'p'); + } + } else { + $file->cleanDirectory(Grap::$storage); + if ($debug) { + Notice::note('Dir: ' . Grap::$storage . ' - content deleted', 'p'); + } } } } diff --git a/app/Console/Commands/Grapper/Sofascore/Helper/RemoveDir.php b/app/Console/Commands/Grapper/Sofascore/Helper/RemoveDir.php new file mode 100644 index 00000000..e469a9ac --- /dev/null +++ b/app/Console/Commands/Grapper/Sofascore/Helper/RemoveDir.php @@ -0,0 +1,23 @@ +first(); @@ -62,6 +62,7 @@ class SetStorage if ($debug) { Notice::note(Grap::$storage, 'g'); + Notice::note(Grap::$folder, 'g'); if (!$force) { sleep(4); } diff --git a/app/Console/Commands/Grapper/Sofascore/MakeExcel.php b/app/Console/Commands/Grapper/Sofascore/MakeExcel.php index 37e45afb..bafd6905 100644 --- a/app/Console/Commands/Grapper/Sofascore/MakeExcel.php +++ b/app/Console/Commands/Grapper/Sofascore/MakeExcel.php @@ -11,9 +11,9 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; class MakeExcel { - public static $max = 1000; + public static $max = 2000; - public static function create() + public static function create(string $what = '') { ini_set('memory_limit', -1); @@ -23,7 +23,12 @@ class MakeExcel Notice::note("Make Excel"); } - $files = ReadDir::get_tree(Grap::$storage); + if ($what == 'day') { + $files = ReadDir::get_tree(Grap::$storage . '/' . Grap::$folder); + } else { + $files = ReadDir::get_tree(Grap::$storage); + } + $files = array_chunk(FileType::filter($files), self::$max);