diff --git a/app/Console/Commands/Grapper/Sofascore.php b/app/Console/Commands/Grapper/Sofascore.php index 75ab5e42..1b63f9d9 100644 --- a/app/Console/Commands/Grapper/Sofascore.php +++ b/app/Console/Commands/Grapper/Sofascore.php @@ -2,10 +2,8 @@ namespace App\Console\Commands\Grapper; -use App\Console\Commands\Grapper\Sofascore\DaysTournament; use App\Console\Commands\Grapper\Sofascore\Grapper; use App\Console\Commands\Grapper\Sofascore\Helper\Strings; -use App\Console\Commands\Grapper\Sofascore\Helper\TaskConfig; use App\Console\Commands\Grapper\Sofascore\PlayerPerSeason; use App\Console\Commands\Grapper\Sofascore\SendMail; use App\Console\Commands\Grapper\Sofascore\SettingsToLocal; @@ -35,20 +33,16 @@ class Sofascore break; case 3: - DaysTournament::run(); - break; - - case 4: self::setStorage(); Grapper::load(); break; - case 5: + case 4: self::setStorage(); ZipFolder::create(self::$storage); break; - case 6: + case 5: self::setStorage(); SendMail::run(); break; @@ -63,7 +57,5 @@ class Sofascore $task = Nuh::$options['task']; self::$storage = storage_path('sofascore_data') . '/' . Strings::clean(SofaScoreTask::where('id', $task)->value('name')); - - dd(self::$storage); } } diff --git a/app/Console/Commands/Grapper/Sofascore/DaysTournament.php b/app/Console/Commands/Grapper/Sofascore/DaysTournament.php index a4908e52..9dd72269 100644 --- a/app/Console/Commands/Grapper/Sofascore/DaysTournament.php +++ b/app/Console/Commands/Grapper/Sofascore/DaysTournament.php @@ -24,153 +24,150 @@ class DaysTournament * Spa La Liga 15-08-2025 - 24-05-2026 * Fra Liggue 15-08-2025 - 17-05-2026 */ - public static function run() + public static function get(array $d) { $debug = Nuh::$options['d'] ?? 0; - $days = LoadDays::load(); - $tournaments_counter = 0; - foreach ($days as $d) { + $sport_id = $d['sport_id']; - $sport_id = $d['sport_id']; - $day = $d['day']; - $slug = $d['slug']; + $day = $d['day']; - $has = SofaScoreDayTournament::where('day', $day)->where('sport_id', $sport_id)->first(); + $slug = $d['slug']; - if ($has) { - if ($debug) { - Notice::note("All tournament for $day have been allready grapped", 'g'); - } - } else { + $has = SofaScoreDayTournament::where('day', $day)->where('sport_id', $sport_id)->first(); - if ($debug) { - Notice::note("$day\ngrappig", 'g'); + if ($has) { + if ($debug) { + Notice::note("Tournaments $day for " . strtoupper($slug) . " allready grapped", 'bb'); + } + } else { + + if ($debug) { + Notice::note("$day\ngrappig", 'g'); + } + + $page = 1; + + while ($page) { + + $url = Nuh::$options['base_url'] . "api/v1/sport/$slug/scheduled-tournaments/$day/page/$page"; + + Sleeper::rand(); + + $data = CurlSofa::load($url); + + if ($data['hasNextPage']) { + $page++; + } else { + $page = false; } - $page = 1; + foreach ($data['scheduled'] as $row) { - while ($page) { - - $url = Nuh::$options['base_url'] . "api/v1/sport/$slug/scheduled-tournaments/$day/page/$page"; - - Sleeper::rand(); - - $data = CurlSofa::load($url); - - if ($data['hasNextPage']) { - $page++; + if (isset($row['tournament']['uniqueTournament'])) { + $tournament = $row['tournament']['uniqueTournament']; } else { - $page = false; + $tournament = $row['tournament']; } - foreach ($data['scheduled'] as $row) { + $category = $tournament['category']; - if (isset($row['tournament']['uniqueTournament'])) { - $tournament = $row['tournament']['uniqueTournament']; - } else { - $tournament = $row['tournament']; - } - - $category = $tournament['category']; - - if ($sport_id == 5) { - $country_id = 470; - } else { - - /** - * CATEGORY - */ - $find = [ - 'Amateur', - 'Bosnia & Herzegovina', - 'Czechia', - 'DR Congo', - 'Netherlands', - 'North & Central America', - 'Bonaire', - 'Sao Tome and Principe', - 'Cape Verde', - 'Macao', - 'Saint Kitts and Nevis', - 'Eswatini', - 'Timor Leste', - 'Laos', - 'Congo Republic', - - ]; - $replace = [ - '', - 'Bosnia Herzegovina', - 'Czech Republic', - 'Congo DR', - 'Holland', - 'North America', - 'Bonaire, Sint Eustatius and Saba', - 'Sao Tome e Principe', - 'Cape Verde Islands', - 'Macau', - 'St. Kitts and Nevis', - 'Swaziland', - 'East Timor', - 'Lao Peoples\'s Democratic Republic', - 'Congo DR', - ]; - $country_id = Country::where('name', trim(str_replace($find, $replace, $category['name'])))->value('id'); - } - - // dd($category, $country_id); - - if (! $country_id) { - // platzhalter fix later sofa_score_categories => txodds countries - // CATEGORY find <-> replace - Log::channel('sofascore')->info($tournament); - - $sofa_score_categorie_id = 10000000; - } else { - $call = SofaScoreCategorie::updateOrCreate([ - 'id' => (int) $category['id'], - 'country_id' => (int) $country_id, - 'slug' => $category['slug'], - ], [ - 'name' => $category['name'], - ]); - - $sofa_score_categorie_id = $call->id; - } + if ($sport_id == 5) { + $country_id = 470; + } else { /** - * TOURNAMENT + * CATEGORY */ - SofaScoreTournament::updateOrCreate([ - 'sport_id' => (int) $sport_id, - 'tournament_id' => (int) $tournament['id'], - 'sofa_score_categorie_id' => (int) $sofa_score_categorie_id, + $find = [ + 'Amateur', + 'Bosnia & Herzegovina', + 'Czechia', + 'DR Congo', + 'Netherlands', + 'North & Central America', + 'Bonaire', + 'Sao Tome and Principe', + 'Cape Verde', + 'Macao', + 'Saint Kitts and Nevis', + 'Eswatini', + 'Timor Leste', + 'Laos', + 'Congo Republic', + + ]; + $replace = [ + '', + 'Bosnia Herzegovina', + 'Czech Republic', + 'Congo DR', + 'Holland', + 'North America', + 'Bonaire, Sint Eustatius and Saba', + 'Sao Tome e Principe', + 'Cape Verde Islands', + 'Macau', + 'St. Kitts and Nevis', + 'Swaziland', + 'East Timor', + 'Lao Peoples\'s Democratic Republic', + 'Congo DR', + ]; + $country_id = Country::where('name', trim(str_replace($find, $replace, $category['name'])))->value('id'); + } + + // dd($category, $country_id); + + if (! $country_id) { + // platzhalter fix later sofa_score_categories => txodds countries + // CATEGORY find <-> replace + Log::channel('sofascore')->info($tournament); + + $sofa_score_categorie_id = 10000000; + } else { + $call = SofaScoreCategorie::updateOrCreate([ + 'id' => (int) $category['id'], + 'country_id' => (int) $country_id, + 'slug' => $category['slug'], ], [ - 'name' => $tournament['name'], - 'slug' => $tournament['slug'], + 'name' => $category['name'], ]); - $tournaments_counter++; + + $sofa_score_categorie_id = $call->id; + } + + /** + * TOURNAMENT + */ + SofaScoreTournament::updateOrCreate([ + 'sport_id' => (int) $sport_id, + 'tournament_id' => (int) $tournament['id'], + 'sofa_score_categorie_id' => (int) $sofa_score_categorie_id, + ], [ + 'name' => $tournament['name'], + 'slug' => $tournament['slug'], + ]); + $tournaments_counter++; // if ($debug) { // Notice::note('tournament: ' . $tournament['name'], 'p'); // } - /** - * DAY TOURNAMENT - */ - SofaScoreDayTournament::updateOrCreate([ - 'tournament_id' => (int) $tournament['id'], - 'sport_id' => (int) $sport_id, - 'day' => $day, - ]); - } + /** + * DAY TOURNAMENT + */ + SofaScoreDayTournament::updateOrCreate([ + 'tournament_id' => (int) $tournament['id'], + 'sport_id' => (int) $sport_id, + 'day' => $day, + ]); + } - if ($debug) { - Notice::note("tournaments: $tournaments_counter", 'p'); - } + if ($debug) { + Notice::note("tournaments: $tournaments_counter", 'p'); } } } diff --git a/app/Console/Commands/Grapper/Sofascore/Grapper.php b/app/Console/Commands/Grapper/Sofascore/Grapper.php index e4fb0b03..5cba83f2 100644 --- a/app/Console/Commands/Grapper/Sofascore/Grapper.php +++ b/app/Console/Commands/Grapper/Sofascore/Grapper.php @@ -16,19 +16,10 @@ use Illuminate\Support\Facades\File; class Grapper { - - /** - * last 3 days = task 1 - * - * nuh --d --f 67 --fun=6 --task=1 - */ - public static function load() { $debug = Nuh::$options['d'] ?? 0; - $force = Nuh::$options['f'] ?? 0; - $task_id = Nuh::$options['task'] ?? 0; $days = LoadDays::load(); @@ -47,15 +38,18 @@ class Grapper if ($debug) Notice::note('Truncate SofaScoreEventGrapped', 'b'); - SofaScoreEventGrapped::query()->truncate(); + SofaScoreEventGrapped::where('grapper_id', $task_id)->delete(); - foreach ($active_tournaments as $tournament) { + foreach ($days as $d) { - if ($debug) { - Notice::note($tournament->tournament->name, 'bg'); - } + DaysTournament::get($d); + + foreach ($active_tournaments as $tournament) { + + if ($debug) { + Notice::note($tournament->tournament->name, 'bg'); + } - foreach ($days as $d) { $day = $d['day']; @@ -95,12 +89,12 @@ class Grapper } $grapped = SofaScoreEventGrapped::firstOrNew(['id' => $event['id']]); + $grapped->grapper_id = $task_id; $grapped->day = $day; $grapped->liga = $event['tournament']['name']; $grapped->name = $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name']; $grapped->url = $url; $grapped->starttime = $starttime->toDateTimeString(); - $grapped->in_current_grapper = true; $folder = Sofascore::$storage . '/' . $day . '/' . $event['tournament']['slug'] . '/' . $event['slug']; diff --git a/app/Console/Commands/Grapper/Sofascore/Helper/LoadDays.php b/app/Console/Commands/Grapper/Sofascore/Helper/LoadDays.php index 5249a516..52fb3463 100644 --- a/app/Console/Commands/Grapper/Sofascore/Helper/LoadDays.php +++ b/app/Console/Commands/Grapper/Sofascore/Helper/LoadDays.php @@ -37,18 +37,6 @@ class LoadDays 'sport_id' => $task->sport_id, 'run_repeatedly' => $task->run_repeatedly, ]; - // $dates[] = [ - // 'day' => Carbon::now()->subDays(2)->format('Y-m-d'), - // 'slug' => $task->sport->ss_slug, - // 'sport_id' => $task->sport_id, - // 'run_repeatedly' => $task->run_repeatedly, - // ]; - // $dates[] = [ - // 'day' => Carbon::now()->subDays(3)->format('Y-m-d'), - // 'slug' => $task->sport->ss_slug, - // 'sport_id' => $task->sport_id, - // 'run_repeatedly' => $task->run_repeatedly, - // ]; break; case 2: diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreTasks/Tables/SofaScoreTasksTable.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreTasks/Tables/SofaScoreTasksTable.php index 718050be..d31d3e76 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreTasks/Tables/SofaScoreTasksTable.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreTasks/Tables/SofaScoreTasksTable.php @@ -2,11 +2,9 @@ namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\Tables; -use App\Models\SofaScoreTask; use Filament\Actions\EditAction; use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\TextColumn; -use Filament\Tables\Columns\ToggleColumn; use Filament\Tables\Table; class SofaScoreTasksTable diff --git a/app/Utilities/ZipFolder.php b/app/Utilities/ZipFolder.php index 025d94f2..cebb40db 100644 --- a/app/Utilities/ZipFolder.php +++ b/app/Utilities/ZipFolder.php @@ -2,7 +2,6 @@ namespace App\Utilities; -use App\Console\Commands\Grapper\Sofascore; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use ZipArchive; diff --git a/database/migrations/2026_07_11_145940_create_sofa_score_event_grappeds_table.php b/database/migrations/2026_07_11_145940_create_sofa_score_event_grappeds_table.php index f9f85850..aba855ac 100644 --- a/database/migrations/2026_07_11_145940_create_sofa_score_event_grappeds_table.php +++ b/database/migrations/2026_07_11_145940_create_sofa_score_event_grappeds_table.php @@ -13,12 +13,12 @@ return new class extends Migration { Schema::create('sofa_score_event_grappeds', function (Blueprint $table) { $table->id(); + $table->integer('grapper_id'); $table->date('day')->nullable(); $table->string('liga')->nullable(); $table->string('name')->nullable(); $table->dateTime('starttime')->nullable(); $table->string('url')->nullable(); - $table->boolean('in_current_grapper')->default(false); $table->boolean('got_statistics')->default(false); $table->boolean('got_lineups')->default(false); $table->boolean('got_odds')->default(false); diff --git a/grapper.sh b/grapper.sh index 2d75a439..5a8d3449 100755 --- a/grapper.sh +++ b/grapper.sh @@ -29,17 +29,14 @@ case "$1" in # echo "\n⚽ close vpn" # killall ssh - # echo "\n⚽ Days Tournament" - # php artisan nuh --d --f 67 --fun=3 --task=$1 - # echo "\n⚽ Grapper" - # php artisan nuh --d --f 67 --fun=4 --task=$1 + php artisan nuh --d --f 67 --fun=3 --task=$1 # echo "\n⚽ CreateZip" - # php artisan nuh --d --f 67 --fun=5 --task=$1 + # php artisan nuh --d --f 67 --fun=4 --task=$1 # echo "\n⚽ SendMail" - # php artisan nuh --d --f 67 --fun=6 --task=$1 + # php artisan nuh --d --f 67 --fun=5 --task=$1 echo "\n😎 done :)" ;;