From 254ca94d73fabfcecc2f464145d85721e78a1ad4 Mon Sep 17 00:00:00 2001 From: salam Date: Sun, 27 Sep 2026 19:43:26 +0200 Subject: [PATCH] wip --- app/Console/Commands/DeleteUnusedFiles.php | 37 ----- app/Console/Commands/Grap.php | 180 --------------------- app/Traits/Sofascore/GrapSofascore.php | 84 +++++++--- app/Traits/Sofascore/GrappingHelper.php | 16 +- 4 files changed, 80 insertions(+), 237 deletions(-) delete mode 100644 app/Console/Commands/DeleteUnusedFiles.php delete mode 100644 app/Console/Commands/Grap.php diff --git a/app/Console/Commands/DeleteUnusedFiles.php b/app/Console/Commands/DeleteUnusedFiles.php deleted file mode 100644 index 90598671..00000000 --- a/app/Console/Commands/DeleteUnusedFiles.php +++ /dev/null @@ -1,37 +0,0 @@ -toArray(); - - collect(Storage::disk('public')->allFiles('statistiko')) - ->reject(fn (string $file) => $file === '.gitignore') - ->reject(fn (string $file) => in_array($file, $tasks)) - ->each(fn ($file) => Storage::disk('public')->delete($file)); - } -} diff --git a/app/Console/Commands/Grap.php b/app/Console/Commands/Grap.php deleted file mode 100644 index 5cfc2e77..00000000 --- a/app/Console/Commands/Grap.php +++ /dev/null @@ -1,180 +0,0 @@ -options(); - self::$options['id'] = (int) $this->argument('id'); - self::$options['day'] = (int) $this->argument('day'); - self::$options['base_url'] = 'https://www.sofascore.com/'; - - if (! self::$options['id']) { - $txt = 'PARAMETERS'.PHP_EOL; - $txt .= '--d debug'.PHP_EOL; - $txt .= '--r restart range'.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 .= '--C clear folder'.PHP_EOL; - $txt .= '--G grap'.PHP_EOL; - $txt .= '--E make excel'.PHP_EOL; - $txt .= '--M mail'.PHP_EOL; - $txt .= '--folder'.PHP_EOL; - $txt .= '-----------------------------------------------------------'.PHP_EOL; - $txt .= 'FUNCTION'.PHP_EOL; - $txt .= ' 1 grapper DAILY & subDays ( default 3)'.PHP_EOL; - $txt .= ' 2 grapper MORE DAYS'.PHP_EOL; - $txt .= ' 3 grapper RANGE'.PHP_EOL; - $txt .= ' 4 grapper ROSE'.PHP_EOL; - $txt .= ' 5 import to excel from folder'.PHP_EOL; - $txt .= ' 7 settings to local'.PHP_EOL; - $txt .= ' 11 move SQL'.PHP_EOL; - $txt .= ' 12 testing url for grapping'.PHP_EOL; - Notice::note($txt, 'b', 1); - } - - Notice::note('Task Id '.self::$options['id'], 'gb'); - - if (self::$options['cear']) { - SetStorage::set(1); - ClearDir::clear(); - } - - if (self::$options['grap']) { - SetStorage::set(1); - Grapper::load(1); - } - - if (self::$options['excel']) { - SetStorage::set(1); - MakeExcel::create(); - } - - if (self::$options['mail']) { - SetStorage::set(1); - SendMail::run(1); - } - - case 4: - // ROSE - SetStorage::set(4); - Rose::run(); - MakeExcel::create(); - - break; - - switch (self::$options['id']) { - - case 1: - // DAILY - - if (self::$options['c']) { - SetStorage::set(1); - ClearDir::clear(); - } - - if (self::$options['C']) { - Grapper::load(1); - } - - if (self::$options['G']) { - Grapper::load(1); - } - - if (self::$options['E']) { - MakeExcel::create(); - } - - if (self::$options['M']) { - SendMail::run(1); - } - - break; - case 2: - // LAST 3 DAYS - self::$options['f'] = 1; - - if (self::$options['c']) { - SetStorage::set(1); - ClearDir::clear(); - } - - self::$options['day'] = 1; - SetStorage::set(1); - Grapper::load(1); - MakeExcel::create('day'); - - self::$options['day'] = 5; - SetStorage::set(1); - Grapper::load(1); - MakeExcel::create('day'); - - SendMail::run(1); - break; - case 3: - // RANGE - SetStorage::set(3); - Grapper::load(3); - MakeExcel::create(); - - break; - case 4: - // ROSE - SetStorage::set(4); - Rose::run(); - MakeExcel::create(); - - break; - case 5: - SetStorage::set(5); - MakeExcel::create(); - - break; - case 7: - - SettingsToLocal::run(); - break; - - case '11': - SqlMover::run(); - break; - - case '12': - GrapperTest::load(); - break; - - default: - Notice::note('function not implemented yet', 'br', 1); - } - } -} diff --git a/app/Traits/Sofascore/GrapSofascore.php b/app/Traits/Sofascore/GrapSofascore.php index c077cddc..7b8f9154 100644 --- a/app/Traits/Sofascore/GrapSofascore.php +++ b/app/Traits/Sofascore/GrapSofascore.php @@ -70,7 +70,7 @@ trait GrapSofascore case 'range': $this->task_id = 3; - $this->run_range($grapperSelected); + $this->range_grapper_nobreak(); break; case 'settings': @@ -91,6 +91,10 @@ trait GrapSofascore $this->clear_folder($folder); break; + + case 'delete_orphants': + $this->delete_imported_files_orphants(); + break; } break; } @@ -116,17 +120,17 @@ trait GrapSofascore /** * day 1 */ - // $this->clear_folder($folder, 'all'); + $this->clear_folder($folder, 'all'); - // $day = Carbon::now()->subDay()->format('Y-m-d'); + $day = Carbon::now()->subDay()->format('Y-m-d'); - // $this->grap_tournaments_for_day($day); + $this->grap_tournaments_for_day($day); - // foreach ($this->tournaments_requested as $tournament) { - // $this->get_event($day, $tournament); - // } + foreach ($this->tournaments_requested as $tournament) { + $this->get_event($day, $tournament); + } - // $this->import_to_excel($day, "Daily-$day"); + $this->import_to_excel($folder, $day); /** * day 5 @@ -135,13 +139,13 @@ trait GrapSofascore $day = Carbon::now()->subDays(5)->format('Y-m-d'); - // $this->grap_tournaments_for_day($day); + $this->grap_tournaments_for_day($day); - // foreach ($this->tournaments_requested as $tournament) { - // $this->get_event($day, $tournament); - // } + foreach ($this->tournaments_requested as $tournament) { + $this->get_event($day, $tournament); + } - $this->import_to_excel($day, "Daily-$day"); + $this->import_to_excel($folder, $day); $this->send($folder); } @@ -176,16 +180,45 @@ trait GrapSofascore /** * Summary of run_range - * - * @return never */ - protected function run_range(string $grapperSelected) + protected function range_grapper_nobreak() { - $this->load_tournaments_requested($grapperSelected); + $folder = 'range'; - $this->load_days($grapperSelected); + $this->task_id = 3; - dd($this->days); + $this->set_base_dir($folder); + + $restart = $this->ask_restart(); + + if ($restart == 'yes') { + $this->restart = 1; + $this->clear_folder($folder, 'all'); + } + + $this->load_tournaments_requested($folder); + + $this->load_days($folder); + + $count = \count($this->days); + foreach ($this->days as $key => $day) { + if ($this->debug) { + $key++; + Notice::note("$key/$count", 'br'); + } + + $this->grap_tournaments_for_day($day); + + foreach ($this->tournaments_requested as $tournament) { + $this->get_event($day, $tournament); + } + } + + Notice::note('Excel', 'g'); + + $this->import_to_excel($folder, $day); + + Notice::note('Done', 'g'); } /** @@ -205,6 +238,7 @@ trait GrapSofascore 'excel' => 'Excel', 'mail' => 'Send Mail', 'clear' => 'Empty Folder', + 'delete_orphants' => 'Delete Imported Orphants', ] ); } @@ -235,6 +269,18 @@ trait GrapSofascore ); } + protected function ask_restart(): string + { + return select( + label: 'Restart Grapper?', + default: 'no', + options: [ + 'yes' => 'Yes', + 'no' => 'No', + ] + ); + } + protected function select_what_delete(): string { return select( diff --git a/app/Traits/Sofascore/GrappingHelper.php b/app/Traits/Sofascore/GrappingHelper.php index d281f3d5..4db70d71 100644 --- a/app/Traits/Sofascore/GrappingHelper.php +++ b/app/Traits/Sofascore/GrappingHelper.php @@ -11,11 +11,13 @@ use App\Models\SofaScoreTask; use App\Models\SofaScoreTaskDay; use App\Models\SofaScoreTaskTournament; use App\Models\SofaScoreTournament; +use App\Models\StatistikoImport; use App\Services\CloudflareSolverService; use App\Utilities\Notice; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Storage; trait GrappingHelper { @@ -125,9 +127,11 @@ trait GrappingHelper { switch ($grapperSelected) { case 'daily': - case 'range': $this->tournaments_requested = SofaScoreTaskTournament::with('tournament')->where('sofa_score_task_id', 1)->where('disabled', false)->get()->toArray(); break; + case 'range': + $this->tournaments_requested = SofaScoreTaskTournament::with('tournament')->where('sofa_score_task_id', 3)->where('disabled', false)->get()->toArray(); + break; } } @@ -420,4 +424,14 @@ trait GrappingHelper break; } } + + protected function delete_imported_files_orphants(): void + { + $tasks = StatistikoImport::pluck('file_name')->toArray(); + + collect(Storage::disk('public')->allFiles('statistiko')) + ->reject(fn (string $file) => $file === '.gitignore') + ->reject(fn (string $file) => in_array($file, $tasks)) + ->each(fn ($file) => Storage::disk('public')->delete($file)); + } }