From 03b3d47151c50b56e77bd9633457c9c05c52eb50 Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 12 Oct 2026 10:59:52 +0200 Subject: [PATCH] wip --- .../Tables/SofaScoreTournamentsTable.php | 4 + app/Models/SofaScoreRosaTournament.php | 1 + app/Traits/Sofascore/GrappingSofascore.php | 7 +- app/Traits/Sofascore/GrappingTeams.php | 102 ++++++++++++++++++ app/Traits/Sofascore/GrappingToExcel.php | 21 ++-- ...13_create_sofa_score_tournaments_table.php | 1 + ...9_132627_create_rosa_tournaments_table.php | 27 ----- 7 files changed, 129 insertions(+), 34 deletions(-) create mode 100644 app/Traits/Sofascore/GrappingTeams.php delete mode 100644 database/migrations/2026_07_29_132627_create_rosa_tournaments_table.php diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php index 136c0a63..df4f9882 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php @@ -38,6 +38,10 @@ class SofaScoreTournamentsTable ->icon(fn ($record) => $record->sofascore_category->flag) ->sortable(), TextColumn::make('name')->searchable()->sortable(), + // ToggleColumn::make('major') + // ->tooltip('Grapping Rose') + // ->alignCenter() + // ->sortable(), ToggleColumn::make('enabled') ->label('In Statistiko') ->alignCenter() diff --git a/app/Models/SofaScoreRosaTournament.php b/app/Models/SofaScoreRosaTournament.php index db8a9058..cec3f62d 100644 --- a/app/Models/SofaScoreRosaTournament.php +++ b/app/Models/SofaScoreRosaTournament.php @@ -12,6 +12,7 @@ class SofaScoreRosaTournament extends Model protected $fillable = [ 'ss_team_id', 'ss_tournament_id', + 'major', 'grapped', 'disabled', ]; diff --git a/app/Traits/Sofascore/GrappingSofascore.php b/app/Traits/Sofascore/GrappingSofascore.php index 9c2da614..e9f2fcd0 100644 --- a/app/Traits/Sofascore/GrappingSofascore.php +++ b/app/Traits/Sofascore/GrappingSofascore.php @@ -19,6 +19,7 @@ trait GrappingSofascore use GrappingEvent; use GrappingHelper; use GrappingMail; + use GrappingTeams; use GrappingToExcel; use GrappingTournaments; @@ -82,6 +83,10 @@ trait GrappingSofascore $this->range_grapper_nobreak(); break; + case 'rose': + $this->team_rose(); + break; + case 'settings': $this->settings_to_local(); break; @@ -299,7 +304,7 @@ trait GrappingSofascore options: [ 'daily' => 'Select day back', 'range' => 'Range', - 'rose' => 'Rose', + 'rose' => 'Rose Teams', 'player' => 'Player', 'settings' => 'Settings', 'excel' => 'Excel', diff --git a/app/Traits/Sofascore/GrappingTeams.php b/app/Traits/Sofascore/GrappingTeams.php new file mode 100644 index 00000000..cbcfe9d7 --- /dev/null +++ b/app/Traits/Sofascore/GrappingTeams.php @@ -0,0 +1,102 @@ +select_what_to_grap(); + + if ($this->restart) { + SofaScoreRosa::query()->update(['grapped' => 0]); + $this->clear_folder($this->data_dir, 'all'); + } + + switch ($what) { + case 'major': + $tournaments = SofaScoreTournament::where('enabled', 1)->whereIn('tournament_id', $major)->pluck('tournament_id')->toArray(); + break; + + default: + $tournaments = SofaScoreTournament::where('enabled', 1)->whereNotIn('tournament_id', $major)->pluck('tournament_id')->toArray(); + break; + } + + $tmp = SofaScoreRosaTournament::whereIn('ss_tournament_id', $tournaments)->pluck('ss_team_id')->toArray(); + + $teams = SofaScoreRosa::where('is_active', 1)->whereIn('ss_team_id', $tmp)->where('grapped', 0)->get(); + + $count = \count($teams); + + $cloudflareService = new CloudflareSolverService; + + foreach ($teams as $key => $value) { + + if ($this->debug) { + $key++; + echo "\n$key/$count\n"; + } + + $url = $this->base_url."api/v1/team/$value->ss_team_id/players"; + + if ($this->debug) { + Notice::note($url, 'b'); + } + + $data = $cloudflareService->getJsonFromUrl($url); + + $data['ss_team_id'] = $value->ss_team_id; + + $data['ss_team_name'] = $value->ss_team_name; + + /********************************* + * add team to folder + *********************************/ + + File::put($this->data_dir.'/'.Strings::clean($value->ss_team_name).'.json', json_encode($data)); + + SofaScoreRosa::where('id', $value->id)->update(['grapped' => 1]); + + $this->sleep(); + } + + $this->import_to_excel("rose_$what"); + + if ($this->debug) { + Notice::note('DONE', 'bb'); + } + } + + protected function select_what_to_grap(): string + { + return select( + label: 'What teams should be grapped?', + options: [ + 'major' => 'Major Leagues', + 'others' => 'Others Leagues', + ] + ); + } +} diff --git a/app/Traits/Sofascore/GrappingToExcel.php b/app/Traits/Sofascore/GrappingToExcel.php index ad4ac4f8..71fb5aff 100644 --- a/app/Traits/Sofascore/GrappingToExcel.php +++ b/app/Traits/Sofascore/GrappingToExcel.php @@ -4,9 +4,10 @@ namespace App\Traits\Sofascore; use App\Models\SofaScoreTask; use App\Utilities\Notice; +use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\File; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -use Illuminate\Support\Facades\File; trait GrappingToExcel { @@ -26,15 +27,23 @@ trait GrappingToExcel case 'daily': $directories = File::directories($this->data_dir); foreach ($directories as $directory) { - $day = substr(strrchr($directory, "/"), 1); - $this->titel = ucfirst($folder) . '-' . $day; - $this->make_file($this->data_dir . '/' . $day); + $day = substr(strrchr($directory, '/'), 1); + $this->titel = ucfirst($folder).'-'.$day; + $this->make_file($this->data_dir.'/'.$day); } break; case 'range': $task = SofaScoreTask::with('sport')->where('id', 3)->first(); - $this->titel = ucfirst($folder) . '-' . $this->clean_string($task->name); + $this->titel = ucfirst($folder).'-'.$this->clean_string($task->name); + $this->make_file($this->data_dir); + break; + + case 'rose_major': + case 'rose_others': + $day = Carbon::now()->subDay()->format('Y-m-d'); + + $this->titel = ucfirst($folder).'-'.$day; $this->make_file($this->data_dir); break; } @@ -67,7 +76,7 @@ trait GrappingToExcel } $spreadsheet = new Spreadsheet; - $spreadsheet->getProperties()->setTitle($this->titel . '-' . $count_from . '-' . $count_to); + $spreadsheet->getProperties()->setTitle($this->titel.'-'.$count_from.'-'.$count_to); $activeWorksheet = $spreadsheet->getActiveSheet(); $column = 1; diff --git a/database/migrations/2026_06_06_134913_create_sofa_score_tournaments_table.php b/database/migrations/2026_06_06_134913_create_sofa_score_tournaments_table.php index c55ac7a0..1c752c20 100644 --- a/database/migrations/2026_06_06_134913_create_sofa_score_tournaments_table.php +++ b/database/migrations/2026_06_06_134913_create_sofa_score_tournaments_table.php @@ -18,6 +18,7 @@ return new class extends Migration $table->integer('sofa_score_category_id')->index(); $table->string('slug')->index(); $table->string('name'); + $table->boolean('major')->index()->default(0); $table->boolean('enabled')->index()->default(0); $table->boolean('disabled')->index()->default(0); $table->timestamps(); diff --git a/database/migrations/2026_07_29_132627_create_rosa_tournaments_table.php b/database/migrations/2026_07_29_132627_create_rosa_tournaments_table.php deleted file mode 100644 index 71f45177..00000000 --- a/database/migrations/2026_07_29_132627_create_rosa_tournaments_table.php +++ /dev/null @@ -1,27 +0,0 @@ -id(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('rosa_tournaments'); - } -};