diff --git a/app/Console/Commands/Grapper/Sofascore/Special.php b/app/Console/Commands/Grapper/Sofascore/Special.php index a18f6177..9872b587 100644 --- a/app/Console/Commands/Grapper/Sofascore/Special.php +++ b/app/Console/Commands/Grapper/Sofascore/Special.php @@ -3,9 +3,10 @@ namespace App\Console\Commands\Grapper\Sofascore; use App\Console\Commands\Grapper\Sofascore\Specials\CreateZip; -use App\Console\Commands\Grapper\Sofascore\Specials\LeaguesToLocal; +use App\Console\Commands\Grapper\Sofascore\Specials\DaysTournament; use App\Console\Commands\Grapper\Sofascore\Specials\PlayerPerSeason; use App\Console\Commands\Grapper\Sofascore\Specials\SendMail; +use App\Console\Commands\Grapper\Sofascore\Specials\SettingsToLocal; use App\Console\Commands\Nuh; use App\Utilities\Notice; @@ -39,7 +40,7 @@ class Special if($debug){ Notice::note('copy active tournament to local', 'y'); } - LeaguesToLocal::run(); + SettingsToLocal::run(); break; case 3: if($debug){ @@ -53,6 +54,13 @@ class Special } SendMail::run(); break; + case 5: + if($debug){ + Notice::note('grap tornamenst available for given day', 'y'); + } + DaysTournament::run(); + break; + default: Notice::note('run special "prc" id missing', 'br', 1); } diff --git a/app/Console/Commands/Grapper/Sofascore/Specials/DaysTournament.php b/app/Console/Commands/Grapper/Sofascore/Specials/DaysTournament.php new file mode 100644 index 00000000..ee112819 --- /dev/null +++ b/app/Console/Commands/Grapper/Sofascore/Specials/DaysTournament.php @@ -0,0 +1,153 @@ +ss_slug/scheduled-tournaments/$day/page/$page"; + + $rand = rand(500000, 1000000); + if ($debug) { + Notice::note("Sleep $rand msec", 'y'); + } + usleep($rand); + + $data = CurlSofa::load($url); + + if ($data['hasNextPage']) { + $page++; + } else { + $page = false; + } + + // $page = false; + + foreach ($data['scheduled'] as $row) { + + 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; + } + + /** + * 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++; + + /** + * DAY TOURNAMENT + */ + + SofaScoreDayTournament::updateOrCreate([ + 'tournament_id' => (int) $tournament['id'], + 'day' => $day, + ]); + } + + if ($debug) { + Notice::note("tournaments: $tournaments_counter", 'p'); + } + + } + } + + + Notice::note('Archive created', 'g', 1); + } +} diff --git a/app/Console/Commands/Grapper/Sofascore/Specials/LeaguesToLocal.php b/app/Console/Commands/Grapper/Sofascore/Specials/LeaguesToLocal.php deleted file mode 100644 index 63564b6f..00000000 --- a/app/Console/Commands/Grapper/Sofascore/Specials/LeaguesToLocal.php +++ /dev/null @@ -1,20 +0,0 @@ -table('sofa_score_tournaments')->where('enabled', 1)->pluck('id'); - - SofaScoreTournament::query()->update(['enabled' => 0]); - - foreach ($tornaments as $tornament_id) { - SofaScoreTournament::where('id', $tornament_id)->update(['enabled' => 1]); - } - } -} diff --git a/app/Console/Commands/Grapper/Sofascore/Specials/SettingsToLocal.php b/app/Console/Commands/Grapper/Sofascore/Specials/SettingsToLocal.php new file mode 100644 index 00000000..adb756cd --- /dev/null +++ b/app/Console/Commands/Grapper/Sofascore/Specials/SettingsToLocal.php @@ -0,0 +1,25 @@ +table('sofa_score_tasks')->get(); + foreach ($rows as $row) { + SofaScoreTask::insert((array) $row); + } + + SofaScoreTaskTournament::truncate(); + $rows = DB::connection('remote_mariadb')->table('sofa_score_task_tournaments')->get(); + foreach ($rows as $row) { + SofaScoreTaskTournament::insert((array) $row); + } + } +} diff --git a/app/Console/Commands/Grapper/Sofascore/Tools/LoadDays.php b/app/Console/Commands/Grapper/Sofascore/Tools/LoadDays.php index 61f475fe..97ef3cb9 100644 --- a/app/Console/Commands/Grapper/Sofascore/Tools/LoadDays.php +++ b/app/Console/Commands/Grapper/Sofascore/Tools/LoadDays.php @@ -3,38 +3,85 @@ namespace App\Console\Commands\Grapper\Sofascore\Tools; use App\Console\Commands\Nuh; -use App\Models\SofaScoreDay; +use App\Models\SofaScoreTask; use App\Utilities\Notice; use Illuminate\Support\Carbon; -/** - * FIFA World Cup 16 - * China Super League 649 - * Veikkausliiga 41 -*/ - class LoadDays { public static function load() { $today = Nuh::$options['t'] ?? 0; + $yesterday = Nuh::$options['y'] ?? 0; - $sport_id = Nuh::$options['sport_id']; if($today){ - $days[] = Carbon::now()->format('Y-m-d'); + return [Carbon::now()->format('Y-m-d')]; } else if($yesterday){ - $days[] = Carbon::now()->subDay()->format('Y-m-d'); + return [Carbon::now()->subDay()->format('Y-m-d')]; } else { - $days = SofaScoreDay::where('sport_id', $sport_id)->where('enabled', 1)->pluck('day')->toArray(); - } + + $res = SofaScoreTask::with('sport')->where('is_active', 1)->get(); + $dates = []; + foreach ($res as $row) { - if (! $days) { - Notice::note(__file__.PHP_EOL.'no days', 'r', 1); - } + switch($row->mode){ + case 'yesterday': + $dates[] = [ + 'day' => Carbon::now()->subDay()->format('Y-m-d'), + 'slug' => $row->sport->ss_slug + ]; + break; + case 'date': + $dates[] = [ + 'day' => self::validateDate($row->day_from), + 'slug' => $row->sport->ss_slug + ]; + break; + case 'range': + $from = self::validateDate($row->day_from); + $to = self::validateDate($row->day_to); - return $days; + $from = Carbon::createFromDate($from); + $to = Carbon::createFromDate($to); + + $lengthdates = $from->diffInDays($to); + + if($lengthdates < 1){ + Notice::note('wrong date start must be before end', 'r', 1); + } + else if($lengthdates > 60){ + Notice::note('wrong date maximal 60 dates allowed', 'r', 1); + } + while ($from < $to){ + $dates[] = [ + 'day' => $from->format('Y-m-d'), + 'slug' => $row->sport->ss_slug + ]; + $from->addDay(); + } + } + + if (! $dates) { + Notice::note(__file__.PHP_EOL.'no dates', 'r', 1); + } + } + } + // remove when element in array is double (day and slug) + $dates = array_unique($dates, SORT_REGULAR); + + return $dates; + } + + public static function validateDate(string $date) + { + if(Carbon::createFromDate($date) !== false){ + return $date; + } + else { + Notice::note('Wrong date format','r', 1); + } } } diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php index 6eca5b6c..5d734214 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/Tables/SofaScoreTournamentsTable.php @@ -103,18 +103,18 @@ class SofaScoreTournamentsTable $query->where('sofa_score_categorie_id', $sofa_score_categorie_id); } } - )->when( - $data['filter-grapping'], - function (Builder $query, $filtergrapping) { - switch ($filtergrapping) { - case 'active': - $query->where('enabled', 1); - break; - case 'disabled': - $query->where('enabled', 0); - break; - } - } + // )->when( + // $data['filter-grapping'], + // function (Builder $query, $filtergrapping) { + // switch ($filtergrapping) { + // case 'active': + // $query->where('enabled', 1); + // break; + // case 'disabled': + // $query->where('enabled', 0); + // break; + // } + // } )->when( $data['filter-disabled'], function (Builder $query, $filterdisabled) { diff --git a/apple_damon.sh b/apple_damon.sh index d21a6c9f..e369b0e5 100755 --- a/apple_damon.sh +++ b/apple_damon.sh @@ -1,7 +1,8 @@ # AUTO GRAPPER SOFASCORE -echo "\n⚽ close all open vpn" -killall ssh + +# echo "\n⚽ close all open vpn" +# killall ssh # echo "\n⚽ open vpn tunnel to prod" # ssh -f -N -L 13306:127.0.0.1:3306 -p 58371 root@162.55.242.190 @@ -12,6 +13,9 @@ killall ssh # echo "\n⚽ close tunnel" # killall ssh +echo "\n⚽ grap avilable tournaments for given day" +php artisan nuh --d --f 73 --prc=5 + # echo "\n⚽ grapp data sofascore" # php artisan nuh --d --f --y 72