diff --git a/app/Console/Commands/Grap.php b/app/Console/Commands/Grap.php index 98d98da2..a2173baf 100644 --- a/app/Console/Commands/Grap.php +++ b/app/Console/Commands/Grap.php @@ -6,6 +6,7 @@ use App\Console\Commands\Grapper\Sofascore\Grapper; use App\Console\Commands\Grapper\Sofascore\Helper\SetStorage; use App\Console\Commands\Grapper\Sofascore\MakeExcel; use App\Console\Commands\Grapper\Sofascore\PlayerPerSeason; +use App\Console\Commands\Grapper\Sofascore\SendMail; use App\Console\Commands\Grapper\Sofascore\SettingsToLocal; use App\Utilities\Notice; use Illuminate\Console\Command; @@ -20,92 +21,110 @@ class Grap extends Command public static string $folder; - public static $id = 0; - public static string $useragent = '4'; - protected $signature = 'grp {id=0} {task=0} {--d} {--r} {--f}'; + protected $signature = 'grp {id=0} {day=0} {--folder=} {--d} {--r} {--f}'; public function handle() { self::$options = $this->options(); - - self::$options['task'] = $this->argument('task'); - + self::$options['id'] = (int) $this->argument('id'); + self::$options['day'] = (int) $this->argument('day'); self::$options['base_url'] = 'https://www.sofascore.com/'; - $id = $this->argument('id'); - - if (!$id) { - $txt = 'PARAMETERS' . PHP_EOL; - $txt .= '--d debug' . PHP_EOL; - $txt .= '--r restart range' . PHP_EOL; - $txt .= '--f force' . PHP_EOL; - $txt .= '-----------------------------------------------------------' . PHP_EOL; - $txt .= 'FUNCTION' . PHP_EOL; - $txt .= " 1\tPlayerPerSeason" . PHP_EOL; - $txt .= " 2\tSettingsToLocal" . PHP_EOL; - $txt .= '-----------------------------------------------------------' . PHP_EOL; - $txt .= 'TASK' . PHP_EOL; - $txt .= " 1\tgrapper daily" . PHP_EOL; - $txt .= " 2\tgrapper" . PHP_EOL; + if (! self::$options['id']) { + $txt = 'PARAMETERS'.PHP_EOL; + $txt .= '--d debug'.PHP_EOL; + $txt .= '--r restart range'.PHP_EOL; + $txt .= '--f force'.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 date'.PHP_EOL; + $txt .= ' 3 grapper range'.PHP_EOL; + $txt .= ' 4 grapper rose'.PHP_EOL; + // $txt .= " 1\tPlayerPerSeason".PHP_EOL; + // $txt .= " 1\tPlayerPerSeason".PHP_EOL; + // $txt .= " 1\tPlayerPerSeason".PHP_EOL; + // $txt .= " 2\tSettingsToLocal".PHP_EOL; Notice::note($txt, 'b', 1); } - switch ($id) { + Notice::note('Id '.self::$options['id'], 'bb'); + sleep(2); + + switch (self::$options['id']) { case 1: - Notice::note('PlayerPerSeason sleep 5', 'bb'); - sleep(5); + // SettingsToLocal::run(); + + SetStorage::set(1); + + // Grapper::load(1); + + // MakeExcel::create(); + + SendMail::run(1); - PlayerPerSeason::run(); break; + // case 2: + // SetStorage::set(); - case 2: - Notice::note('SettingsToLocal sleep 5', 'bb'); - sleep(5); + // Grapper::load(2); + // break; + // case 3: + // SetStorage::set(); - SettingsToLocal::run(); - break; + // Grapper::load(3); + // break; + // case 4: + // SetStorage::set(); - case 3: - SetStorage::set(); - Grapper::load(); - break; + // Grapper::load(4); + // break; + // case 5: - case 4: - SetStorage::set(); - MakeExcel::create(); - break; + // PlayerPerSeason::run(); + // break; - // case 'zip': - // self::setStorage(); - // ZipFolder::create(); - // break; + // case 6: - // case 'mail': - // self::setStorage(); - // SendMail::run(); - // break; + // SettingsToLocal::run(); + // break; - // case 'rose': - // self::setStorage(); - // Rose::run(); - // break; + // case 7: - // case 'sql_mover': - // SqlMover::run(); - // break; + // SetStorage::set(); + // MakeExcel::create(); + // break; + // case 'zip': + // self::setStorage(); + // ZipFolder::create(); + // break; + // case 'mail': + // self::setStorage(); + // SendMail::run(); + // break; - // case 'torunament_teams': - // TournamentTeams::get(); - // break; + // case 'rose': + // self::setStorage(); + // Rose::run(); + // break; - // case 'set_to_production': - // SettingsToProduction::run(); - // break; + // case 'sql_mover': + // SqlMover::run(); + // break; + + // case 'torunament_teams': + // TournamentTeams::get(); + // break; + + // case 'set_to_production': + // SettingsToProduction::run(); + // break; default: Notice::note('not a valid fuction', 'br', 1); diff --git a/app/Console/Commands/Grapper/Sofascore/DaysTournament.php b/app/Console/Commands/Grapper/Sofascore/DaysTournament.php index ae8e889e..d1c6bf8d 100644 --- a/app/Console/Commands/Grapper/Sofascore/DaysTournament.php +++ b/app/Console/Commands/Grapper/Sofascore/DaysTournament.php @@ -2,9 +2,9 @@ namespace App\Console\Commands\Grapper\Sofascore; +use App\Console\Commands\Grap; use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa; use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper; -use App\Console\Commands\Grap; use App\Models\Country; use App\Models\SofaScoreCategory; use App\Models\SofaScoreDayTournament; @@ -16,157 +16,156 @@ class DaysTournament { /** * a Grap --d --f 67 --fun=4 --task=1 - * + * * Ita Serie-A-Saison 23-08-2025 - 24-05-2026 * Ger Bundesliga 22-08-2025 – 16-05-2026 * Eng Premier league 15-08-2025 - 24-05-2026 * Spa La Liga 15-08-2025 - 24-05-2026 * Fra Liggue 15-08-2025 - 17-05-2026 */ - public static function get(array $d) + public static function get(string $day) { $debug = Grap::$options['d'] ?? 0; $tournaments_counter = 0; - $sport_id = $d['sport_id']; + $has = SofaScoreDayTournament::where('day', $day)->first(); - $day = $d['day']; + $sport = []; + $sport[1] = 'football'; - $slug = $d['slug']; + foreach ($sport as $sport_id => $slug) { + if ($has) { + if ($debug) { + Notice::note("Tournaments $day for ".strtoupper($slug).' allready grapped', 'bb'); + } + } else { - $has = SofaScoreDayTournament::where('day', $day)->where('sport_id', $sport_id)->first(); - - 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 = Grap::$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; + if ($debug) { + Notice::note("$day\ngrappig", 'g'); } - foreach ($data['scheduled'] as $row) { + $page = 1; - if (isset($row['tournament']['uniqueTournament'])) { - $tournament = $row['tournament']['uniqueTournament']; + while ($page) { + + $url = Grap::$options['base_url']."api/v1/sport/$slug/scheduled-tournaments/$day/page/$page"; + + Sleeper::rand(); + + $data = CurlSofa::load($url); + + if ($data['hasNextPage']) { + $page++; } else { - $tournament = $row['tournament']; + $page = false; } - $category = $tournament['category']; + foreach ($data['scheduled'] as $row) { - if ($sport_id == 5) { - $country_id = 470; - } else { + 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_category_id = 10000000; + } else { + $call = SofaScoreCategory::updateOrCreate([ + 'id' => (int) $category['id'], + 'country_id' => (int) $country_id, + 'slug' => $category['slug'], + ], [ + 'name' => $category['name'], + ]); + + $sofa_score_category_id = $call->id; + } /** - * CATEGORY + * TOURNAMENT */ - $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_category_id = 10000000; - } else { - $call = SofaScoreCategory::updateOrCreate([ - 'id' => (int) $category['id'], - 'country_id' => (int) $country_id, - 'slug' => $category['slug'], + SofaScoreTournament::updateOrCreate([ + 'sport_id' => (int) $sport_id, + 'tournament_id' => (int) $tournament['id'], + 'sofa_score_category_id' => (int) $sofa_score_category_id, ], [ - 'name' => $category['name'], + 'name' => $tournament['name'], + 'slug' => $tournament['slug'], ]); - - $sofa_score_category_id = $call->id; - } - - /** - * TOURNAMENT - */ - SofaScoreTournament::updateOrCreate([ - 'sport_id' => (int) $sport_id, - 'tournament_id' => (int) $tournament['id'], - 'sofa_score_category_id' => (int) $sofa_score_category_id, - ], [ - 'name' => $tournament['name'], - 'slug' => $tournament['slug'], - ]); - $tournaments_counter++; + $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 8992fefc..f3410d19 100644 --- a/app/Console/Commands/Grapper/Sofascore/Grapper.php +++ b/app/Console/Commands/Grapper/Sofascore/Grapper.php @@ -3,20 +3,20 @@ namespace App\Console\Commands\Grapper\Sofascore; use App\Console\Commands\Grap; -use App\Utilities\Notice; -use Illuminate\Support\Carbon; -use App\Models\SofaScoreTaskDay; -use Illuminate\Support\Facades\File; -use App\Models\SofaScoreEventGrapped; -use App\Models\SofaScoreDayTournament; -use App\Models\SofaScoreTaskTournament; -use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper; use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa; use App\Console\Commands\Grapper\Sofascore\Helper\LoadDays; +use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper; +use App\Models\SofaScoreDayTournament; +use App\Models\SofaScoreEventGrapped; +use App\Models\SofaScoreTaskDay; +use App\Models\SofaScoreTaskTournament; +use App\Utilities\Notice; +use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\File; class Grapper { - public static function load() + public static function load(int $task_id) { /** * , JSON_PRETTY_PRINT @@ -25,12 +25,12 @@ class Grapper $debug = Grap::$options['d'] ?? 0; $restart = Grap::$options['r'] ?? 0; $force = Grap::$options['f'] ?? 0; - $task_id = Grap::$options['task'] ?? 0; - if (!$task_id) + if (! $task_id) { Notice::note('task id missing', 'r', 1); + } - $days = LoadDays::load(); + $days = LoadDays::load($task_id); $count = 0; @@ -39,18 +39,21 @@ class Grapper /** * daily restart always */ - if ($task_id == 1) SofaScoreEventGrapped::where('grapper_id', $task_id)->delete(); + if ($task_id == 1) { + SofaScoreEventGrapped::where('grapper_id', $task_id)->delete(); + } /** + * Restart RANGE call * empty grapping folder - * empty mailing text + * empty mail text */ if ($restart) { SofaScoreEventGrapped::where('grapper_id', $task_id)->delete(); - foreach ($days as $d) { + foreach ($days as $day) { SofaScoreTaskDay::where('grapper_id', (int) $task_id) - ->where('day', $d['day']) + ->where('day', $day) ->update(['done' => 0]); } @@ -63,16 +66,14 @@ class Grapper } } - foreach ($days as $d) { + foreach ($days as $day) { - DaysTournament::get($d); + DaysTournament::get($day); foreach ($active_tournaments as $tournament) { - $day = $d['day']; - if ($debug) { - Notice::note('START ' . $tournament->tournament->name, 'p'); + Notice::note('START '.$tournament->tournament->name, 'p'); } $res = SofaScoreDayTournament::whereDate('day', '=', $day)->where('tournament_id', $tournament->sofa_score_tournament_id)->first(); @@ -83,7 +84,7 @@ class Grapper Notice::note($day, 'g'); } - $url = Grap::$options['base_url'] . "api/v1/unique-tournament/$tournament->sofa_score_tournament_id/scheduled-events/$day"; + $url = Grap::$options['base_url']."api/v1/unique-tournament/$tournament->sofa_score_tournament_id/scheduled-events/$day"; Sleeper::rand(1); @@ -95,9 +96,9 @@ class Grapper Grap::$useragent = rand(1, 6); - if (!$force && SofaScoreEventGrapped::where('id', (int) $event['id'])->exists()) { + if (! $force && SofaScoreEventGrapped::where('id', (int) $event['id'])->exists()) { if ($debug) { - Notice::note('Grapped ' . $day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'g'); + Notice::note('Grapped '.$day.' - '.$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'g'); } } else { @@ -112,18 +113,18 @@ class Grapper Sleeper::rand(1); if ($debug) { - Notice::note($day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'bg'); + Notice::note($day.' - '.$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'bg'); } - $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 = 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(); - $folder = Grap::$storage . '/' . $day . '/' . $day . '-' . $event['tournament']['slug'] . '/' . $event['slug']; + $folder = Grap::$storage.'/'.$day.'/'.$day.'-'.$event['tournament']['slug'].'/'.$event['slug']; File::makeDirectory($folder, 0775, true, true); @@ -131,7 +132,7 @@ class Grapper * EVENT event *********************************/ - File::put($folder . '/event.json', json_encode($event)); + File::put($folder.'/event.json', json_encode($event)); /********************************* * EVENT statistics @@ -139,7 +140,7 @@ class Grapper $event_id = $event['id']; - $url = Grap::$options['base_url'] . "api/v1/event/$event_id/statistics"; + $url = Grap::$options['base_url']."api/v1/event/$event_id/statistics"; Sleeper::rand(); @@ -147,7 +148,7 @@ class Grapper $data['id'] = $event_id; - File::put($folder . '/statistics.json', json_encode($data)); + File::put($folder.'/statistics.json', json_encode($data)); $grapped->got_statistics = 1; @@ -155,7 +156,7 @@ class Grapper * EVENT lineups *********************************/ - $url = Grap::$options['base_url'] . "api/v1/event/$event_id/lineups"; + $url = Grap::$options['base_url']."api/v1/event/$event_id/lineups"; Sleeper::rand(); @@ -163,7 +164,7 @@ class Grapper $data['id'] = $event_id; - File::put($folder . '/lineups.json', json_encode($data)); + File::put($folder.'/lineups.json', json_encode($data)); $grapped->got_lineups = 1; @@ -171,7 +172,7 @@ class Grapper * EVENT odds *********************************/ - $url = Grap::$options['base_url'] . "api/v1/event/$event_id/odds/1/all"; + $url = Grap::$options['base_url']."api/v1/event/$event_id/odds/1/all"; Sleeper::rand(); @@ -179,7 +180,7 @@ class Grapper $data['id'] = $event_id; - File::put($folder . '/odds.json', json_encode($data)); + File::put($folder.'/odds.json', json_encode($data)); $grapped->got_odds = 1; @@ -187,7 +188,7 @@ class Grapper * EVENT incidents *********************************/ - $url = Grap::$options['base_url'] . "api/v1/event/$event_id/incidents"; + $url = Grap::$options['base_url']."api/v1/event/$event_id/incidents"; Sleeper::rand(); @@ -195,7 +196,7 @@ class Grapper $data['id'] = $event_id; - File::put($folder . '/incidents.json', json_encode($data)); + File::put($folder.'/incidents.json', json_encode($data)); $grapped->got_incidents = 1; @@ -206,7 +207,7 @@ class Grapper } } if ($debug) { - Notice::note('END ' . $tournament->tournament->name, 'p'); + Notice::note('END '.$tournament->tournament->name, 'p'); } } SofaScoreTaskDay::updateOrCreate([ @@ -218,12 +219,10 @@ class Grapper $count++; - Notice::note($count . ' DAYS DONE', 'bb'); + if ($debug) { + Notice::note($count.' days done', 'bb'); + } - // if ($count > 20) - // Notice::note($count . ' DAYS DONE', 'br', 1); - // else - // Notice::note($count . ' DAYS DONE', 'bb'); } } } diff --git a/app/Console/Commands/Grapper/Sofascore/Helper/FileType.php b/app/Console/Commands/Grapper/Sofascore/Helper/FileType.php new file mode 100644 index 00000000..daf61898 --- /dev/null +++ b/app/Console/Commands/Grapper/Sofascore/Helper/FileType.php @@ -0,0 +1,19 @@ +where('id', $task_id)->first(); if ($debug) { - Notice::note('Task id:' . $task->id . ', mode:' . $task->mode . ', sport:' . $task->sport->name); + Notice::note('Task id:'.$task->id.', mode:'.$task->mode.', sport:'.$task->sport->name); } switch ($task->mode) { case 'daily': - if ($folder) { - $dates[] = [ - 'day' => $folder, - 'slug' => $task->sport->ss_slug, - 'sport_id' => $task->sport_id, - ]; - } else { - $dates[] = [ - 'day' => Carbon::now()->subDays(3)->format('Y-m-d'), - 'slug' => $task->sport->ss_slug, - 'sport_id' => $task->sport_id, - ]; - } + $dates[] = ValidateDate::get(Grap::$folder); break; case 'date': - $dates[] = [ - 'day' => self::validateDate($task->day_from), - 'slug' => $task->sport->ss_slug, - 'sport_id' => $task->sport_id, - ]; + $dates[] = ValidateDate::get($task->day_from); break; case 'range': - $from = self::validateDate($task->day_from); - $to = self::validateDate($task->day_to); + $from = ValidateDate::get($task->day_from); + $to = ValidateDate::get($task->day_to); $from = Carbon::createFromDate($from); $to = Carbon::createFromDate($to); @@ -75,25 +56,17 @@ class LoadDays if ($restart) { // get all days while ($from <= $to) { - $dates[] = [ - 'day' => $from->format('Y-m-d'), - 'slug' => $task->sport->ss_slug, - 'sport_id' => $task->sport_id, - ]; + $dates[] = $from->format('Y-m-d'); $from->addDay(); } } else { - // remove days done + // remove days done while ($from <= $to) { $res = SofaScoreTaskDay::firstOrNew(['grapper_id' => (int) $task_id, 'day' => $from->format('Y-m-d')]); - if (!$res->done) { - $dates[] = [ - 'day' => $from->format('Y-m-d'), - 'slug' => $task->sport->ss_slug, - 'sport_id' => $task->sport_id, - ]; + if (! $res->done) { + $dates[] = $from->format('Y-m-d'); } $from->addDay(); } @@ -110,16 +83,6 @@ class LoadDays // 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/Console/Commands/Grapper/Sofascore/Helper/SetStorage.php b/app/Console/Commands/Grapper/Sofascore/Helper/SetStorage.php index 554b2371..82064282 100644 --- a/app/Console/Commands/Grapper/Sofascore/Helper/SetStorage.php +++ b/app/Console/Commands/Grapper/Sofascore/Helper/SetStorage.php @@ -9,47 +9,52 @@ use Illuminate\Support\Carbon; class SetStorage { - public static function set() + public static function set(int $task_id) { - $task = Grap::$options['task'] ?? 1; $debug = Grap::$options['d']; - $folder = Grap::$options['folder'] ?? ''; - $task = SofaScoreTask::where('id', $task)->first(); - $sofascore_data = storage_path('sofascore_data') . '/'; + $folder = Grap::$options['folder'] ?? ''; + + $day = Grap::$options['day'] == 0 ? 3 : Grap::$options['day']; + + // must be connectet to task for activated ligas + $task = SofaScoreTask::where('id', $task_id)->first(); + + $sofascore_data = storage_path('sofascore_data').'/'; if ($task) { $storage_name = Strings::clean($task->name); switch ($task->id) { case 1: - Grap::$storage = $sofascore_data . $storage_name; - Grap::$folder = Carbon::now()->subDays(3)->format('Y-m-d'); + Grap::$storage = $sofascore_data.$storage_name; + Grap::$folder = Carbon::now()->subDays($day)->format('Y-m-d'); break; case 2: - Grap::$storage = $sofascore_data . $storage_name . '/' . $task->day_from; - Grap::$zipfile = $sofascore_data . $storage_name . '/' . $task->day_from . '.zip'; + Grap::$storage = $sofascore_data.$storage_name.'/'.$task->day_from; + Grap::$zipfile = $sofascore_data.$storage_name.'/'.$task->day_from.'.zip'; break; case 3: - Grap::$storage = $sofascore_data . $storage_name . '-' . $task->day_from . '-' . $task->day_to; - Grap::$zipfile = $sofascore_data . $storage_name . '-' . $task->day_from . '-' . $task->day_to . '.zip'; + Grap::$storage = $sofascore_data.$storage_name.'-'.$task->day_from.'-'.$task->day_to; + Grap::$zipfile = $sofascore_data.$storage_name.'-'.$task->day_from.'-'.$task->day_to.'.zip'; break; case 4: - Grap::$storage = $sofascore_data . $storage_name . '/rosa-' . Carbon::now()->format('Y-m-d'); - Grap::$zipfile = $sofascore_data . $storage_name . '/rosa-' . Carbon::now()->format('Y-m-d') . '.zip'; + Grap::$storage = $sofascore_data.$storage_name.'/rosa-'.Carbon::now()->format('Y-m-d'); + Grap::$zipfile = $sofascore_data.$storage_name.'/rosa-'.Carbon::now()->format('Y-m-d').'.zip'; break; default: - Grap::$storage = $sofascore_data . $storage_name; - Grap::$zipfile = $sofascore_data . $storage_name . '/archive.zip'; + Grap::$storage = $sofascore_data.$storage_name; + Grap::$zipfile = $sofascore_data.$storage_name.'/archive.zip'; break; } - } else if ($folder) { + } elseif ($folder) { Grap::$storage = $sofascore_data; Grap::$folder = $folder; } if ($debug) { - Notice::note("Task: $task->name\n" . 'Storage: ' . Grap::$storage . "\nFolder: " . Grap::$folder); + Notice::note("Task: $task->name\n".'Storage: '.Grap::$storage."\nFolder: ".Grap::$folder); + sleep(2); } } } diff --git a/app/Console/Commands/Grapper/Sofascore/Helper/ValidateDate.php b/app/Console/Commands/Grapper/Sofascore/Helper/ValidateDate.php new file mode 100644 index 00000000..f9b4b2ea --- /dev/null +++ b/app/Console/Commands/Grapper/Sofascore/Helper/ValidateDate.php @@ -0,0 +1,18 @@ +open(Sofascore::$zipfile, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) { + if ($zip->open(Grap::$zipfile, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) { - if (is_dir(Sofascore::$storage)) { + if (is_dir(Grap::$storage)) { - $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(Sofascore::$storage)); + $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(Grap::$storage)); foreach ($files as $file) { - if (!$file->isDir()) { + if (! $file->isDir()) { $filePath = $file->getRealPath(); - $relativePath = substr($filePath, strlen(Sofascore::$storage) + 1); + $relativePath = substr($filePath, strlen(Grap::$storage) + 1); $zip->addFile($filePath, $relativePath); } } diff --git a/app/Console/Commands/Grapper/Sofascore/MakeExcel.php b/app/Console/Commands/Grapper/Sofascore/MakeExcel.php index 2528fc68..05d2f270 100644 --- a/app/Console/Commands/Grapper/Sofascore/MakeExcel.php +++ b/app/Console/Commands/Grapper/Sofascore/MakeExcel.php @@ -3,7 +3,7 @@ namespace App\Console\Commands\Grapper\Sofascore; use App\Console\Commands\Grap; -use App\Console\Commands\Grapper\Grap\Helper\ZipFolder; +use App\Console\Commands\Grapper\Sofascore\Helper\FileType; use App\Console\Commands\Grapper\Sofascore\Helper\ReadDir; use App\Console\Commands\Nuh; use App\Utilities\Notice; @@ -18,27 +18,29 @@ class MakeExcel public static function create() { - ini_set("memory_limit", -1); + ini_set('memory_limit', -1); $debug = Nuh::$options['d'] ?? 0; if ($debug) { - Notice::note("Make Excel folder to import: " . Grap::$folder . "\nmaximum files in excel: " . self::$max, 'b'); + Notice::note('Make Excel folder to import: '.Grap::$folder."\nmaximum files in excel: ".self::$max, 'b'); } - $files = self::load_files(); + $files = ReadDir::get_tree(Grap::$storage.'/'.Grap::$folder); + + $files = array_chunk(FileType::filter($files), self::$max); foreach ($files as $key => $value) { $has = count($value); - if (!$key && $has < self::$max) { + if (! $key && $has < self::$max) { $from = 1; $to = $has; - } else if (!$key) { + } elseif (! $key) { $from = 1; $key++; $to = $key * self::$max; - } else if ($has == self::$max) { + } elseif ($has == self::$max) { $from = $key * self::$max + 1; $key++; $to = $key * self::$max; @@ -47,7 +49,7 @@ class MakeExcel $to = $key * self::$max + $has; } - $filename = Grap::$folder . '-' . $from . '-' . $to . '.xlsx'; + $filename = Grap::$folder.'-'.$from.'-'.$to.'.xlsx'; $spreadsheet = new Spreadsheet; $spreadsheet->getProperties()->setTitle($filename); $activeWorksheet = $spreadsheet->getActiveSheet(); @@ -69,24 +71,9 @@ class MakeExcel $spreadsheet->setActiveSheetIndex(0); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); - $writer->save(Grap::$storage . '/' . $filename); + $writer->save(Grap::$storage.'/'.$filename); - self::$filesToMail[] = Grap::$storage . '/' . $filename; + self::$filesToMail[] = Grap::$storage.'/'.$filename; } } - - - public static function load_files() - { - $files = ReadDir::get_tree(Grap::$storage . '/' . Grap::$folder); - - $filtered = []; - foreach ($files as $file) { - $path_parts = pathinfo($file); - if (isset($path_parts['extension']) && $path_parts['extension'] == 'json') { - $filtered[] = $file; - } - } - return array_chunk($filtered, self::$max); - } } diff --git a/app/Console/Commands/Grapper/Sofascore/SendMail.php b/app/Console/Commands/Grapper/Sofascore/SendMail.php index 50cc8b09..db97b034 100644 --- a/app/Console/Commands/Grapper/Sofascore/SendMail.php +++ b/app/Console/Commands/Grapper/Sofascore/SendMail.php @@ -2,81 +2,71 @@ namespace App\Console\Commands\Grapper\Sofascore; -use App\Console\Commands\Nuh; +use App\Console\Commands\Grap; +use App\Console\Commands\Grapper\Sofascore\Helper\FileType; +use App\Console\Commands\Grapper\Sofascore\Helper\ReadDir; use App\Mail\SofaScoreDataMail; use App\Models\SofaScoreEventGrapped; -use App\Utilities\Notice; -use Illuminate\Support\Facades\File; -use Illuminate\Support\Facades\Mail; -use App\Console\Commands\Grapper\Sofascore; use App\Models\SofaScoreTask; +use App\Utilities\Notice; use Carbon\Carbon; +use Illuminate\Support\Facades\Mail; class SendMail { - public static function run() + public static function run(int $task_id) { - $debug = Nuh::$options['d'] ?? 0; - - $task_id = Nuh::$options['task'] ?? 0; + $debug = Grap::$options['d'] ?? 0; $task = SofaScoreTask::where('id', $task_id)->first(); - $zip_file = Sofascore::$storage . Sofascore::$archive_name; + $files = ReadDir::get_tree(Grap::$storage); + + $sendfiles = FileType::filter($files, 'xlsx'); $header = self::createHeader($task); - $message = self::createMessage($task); + $table = self::createTable($task); - if (File::exists($zip_file)) { - - Mail::to('hermann.telser@gmail.com') - ->cc('ubaldo.perrucci@gmail.com') - ->send( - new SofaScoreDataMail($header, $message) - ); - if ($debug) { - Notice::note('Mail: ' . $header); - } - } else { - if ($debug) { - Notice::note('zip not found ' . $zip_file, 'r', 1); - } + Mail::to('hermann.telser@gmail.com') + ->cc('ubaldo.perrucci@gmail.com') + ->send( + new SofaScoreDataMail($header, $table, $sendfiles) + ); + if ($debug) { + Notice::note('Mail: '.$header); } if ($debug) { - Notice::note('Mail send', 'g'); + Notice::note('mail send', 'g'); } } - public static function createMessage(SofaScoreTask $task) + public static function createTable(SofaScoreTask $task) { $res = SofaScoreEventGrapped::where('grapper_id', $task->id)->get(); - $text = ' - - '; - + $table = ''; foreach ($res as $value) { - $text .= $value->liga . ' - ' . $value->name . ' - ' . $value->starttime; - $text .= ' - '; + $table .= '|'.$value->liga.'|'.$value->name.'|'.$value->starttime.'| + '; } - return $text; + + return $table; } public static function createHeader(SofaScoreTask $task) { - $text = "## "; + $text = '## '; switch ($task->mode) { case 'daily': - $text = $task->name . ' - ' . Carbon::now()->subDays(3)->format('Y-m-d'); + $text = $task->name.' - '.Carbon::now()->subDays(3)->format('Y-m-d'); break; case 'date': - $text = $task->name . ' - ' . $task->day_from; + $text = $task->name.' - '.$task->day_from; break; case 'range': - $text = $task->name . ' - ' . $task->day_from . ' - ' . $task->day_to; + $text = $task->name.' - '.$task->day_from.' - '.$task->day_to; break; default: diff --git a/app/Console/Commands/Nuh.php b/app/Console/Commands/Nuh.php index be282f4e..9cec5b51 100644 --- a/app/Console/Commands/Nuh.php +++ b/app/Console/Commands/Nuh.php @@ -2,19 +2,19 @@ namespace App\Console\Commands; -use App\Utilities\Notice; -use App\Models\Supervisor; -use Illuminate\Console\Command; -use App\Utilities\Supervisorctl; -use Illuminate\Support\Facades\DB; +use App\Console\Commands\DbMapper\AutoMapper; use App\Console\Commands\Grapper\Betica; -use App\Console\Commands\Grapper\Magloo; -use App\Console\Commands\Grapper\TxOdds; use App\Console\Commands\Grapper\Betsapi; use App\Console\Commands\Grapper\Goldbet; -use App\Console\Commands\Services\Services; use App\Console\Commands\Grapper\Logifuture; -use App\Console\Commands\DbMapper\AutoMapper; +use App\Console\Commands\Grapper\Magloo; +use App\Console\Commands\Grapper\TxOdds; +use App\Console\Commands\Services\Services; +use App\Models\Supervisor; +use App\Utilities\Notice; +use App\Utilities\Supervisorctl; +use Illuminate\Console\Command; +use Illuminate\Support\Facades\DB; class Nuh extends Command { @@ -22,7 +22,7 @@ class Nuh extends Command public static $id = 0; - protected $signature = 'nuh {process=help} {--folder=} {--id=0} {--gid=} {--p} {--d} {--x} {--t} {--y} {--m} {--l} {--w} {--a} {--r} {--s} {--g} {--t} {--q} {--f} {--b} {--e} {--z}'; + protected $signature = 'nuh {process=help} {--id=0} {--gid=} {--p} {--d} {--x} {--t} {--y} {--m} {--l} {--w} {--a} {--r} {--s} {--g} {--t} {--q} {--f} {--b} {--e} {--z}'; public function handle() { @@ -35,45 +35,45 @@ class Nuh extends Command if ($this->argument('process') == 'help') { $txt = PHP_EOL; - if (!$show_supervisors) { - $txt .= 'Parameters' . PHP_EOL; - $txt .= '-----------------------------------------------------------' . PHP_EOL; - $txt .= 'process [id] (required)' . PHP_EOL; - $txt .= '--id=matchid (optional) calling spezific id' . PHP_EOL; - $txt .= '--fun=name (optional) [bkms, markets]' . PHP_EOL; - $txt .= '--gid=groupid (optional) [bkms, groupid]' . PHP_EOL; - $txt .= '-----------------------------------------------------------' . PHP_EOL . PHP_EOL; - $txt .= 'Options' . PHP_EOL; - $txt .= '-----------------------------------------------------------' . PHP_EOL; - $txt .= '--a all by id' . PHP_EOL; - $txt .= '--b block update (reload all for txodds)' . PHP_EOL; - $txt .= '--d debug' . PHP_EOL; - $txt .= '--e echo client data' . PHP_EOL; - $txt .= '--f force (what ever in script)' . PHP_EOL; - $txt .= '--g by minor groups (tx)' . PHP_EOL; - $txt .= '--t load today' . PHP_EOL; - $txt .= '--m mail it' . PHP_EOL; - $txt .= '--p use proxy' . PHP_EOL; - $txt .= '--q print all queries' . PHP_EOL; - $txt .= '--r read data from file ' . PHP_EOL; - $txt .= '--s store data to file ' . PHP_EOL; - $txt .= '--t load today' . PHP_EOL; - $txt .= '--w laod this week (tx)' . PHP_EOL; - $txt .= '--x generate supervisors' . PHP_EOL; - $txt .= '--y load yesterday' . PHP_EOL; - $txt .= '--z show supervisors tasks' . PHP_EOL; + if (! $show_supervisors) { + $txt .= 'Parameters'.PHP_EOL; + $txt .= '-----------------------------------------------------------'.PHP_EOL; + $txt .= 'process [id] (required)'.PHP_EOL; + $txt .= '--id=matchid (optional) calling spezific id'.PHP_EOL; + $txt .= '--fun=name (optional) [bkms, markets]'.PHP_EOL; + $txt .= '--gid=groupid (optional) [bkms, groupid]'.PHP_EOL; + $txt .= '-----------------------------------------------------------'.PHP_EOL.PHP_EOL; + $txt .= 'Options'.PHP_EOL; + $txt .= '-----------------------------------------------------------'.PHP_EOL; + $txt .= '--a all by id'.PHP_EOL; + $txt .= '--b block update (reload all for txodds)'.PHP_EOL; + $txt .= '--d debug'.PHP_EOL; + $txt .= '--e echo client data'.PHP_EOL; + $txt .= '--f force (what ever in script)'.PHP_EOL; + $txt .= '--g by minor groups (tx)'.PHP_EOL; + $txt .= '--t load today'.PHP_EOL; + $txt .= '--m mail it'.PHP_EOL; + $txt .= '--p use proxy'.PHP_EOL; + $txt .= '--q print all queries'.PHP_EOL; + $txt .= '--r read data from file '.PHP_EOL; + $txt .= '--s store data to file '.PHP_EOL; + $txt .= '--t load today'.PHP_EOL; + $txt .= '--w laod this week (tx)'.PHP_EOL; + $txt .= '--x generate supervisors'.PHP_EOL; + $txt .= '--y load yesterday'.PHP_EOL; + $txt .= '--z show supervisors tasks'.PHP_EOL; } - $txt .= '-----------------------------------------------------------' . PHP_EOL . PHP_EOL; - $txt .= 'Supervisors (--z)' . PHP_EOL; + $txt .= '-----------------------------------------------------------'.PHP_EOL.PHP_EOL; + $txt .= 'Supervisors (--z)'.PHP_EOL; if ($show_supervisors) { - $txt .= '-----------------------------------------------------------' . PHP_EOL; + $txt .= '-----------------------------------------------------------'.PHP_EOL; $tmp = Supervisor::orderBy('provider_id')->get(); foreach ($tmp as $value) { if ($value->sport_id) { - $txt .= sprintf('% 3d', $value->id) . ' ' . $value->provider->name . ' - ' . $value->sport->name . ' ' . $value->name . PHP_EOL; + $txt .= sprintf('% 3d', $value->id).' '.$value->provider->name.' - '.$value->sport->name.' '.$value->name.PHP_EOL; } else { - $txt .= sprintf('% 3d', $value->id) . ' ' . $value->provider->name . ' - All ' . $value->name . PHP_EOL; + $txt .= sprintf('% 3d', $value->id).' '.$value->provider->name.' - All '.$value->name.PHP_EOL; } } } diff --git a/app/Mail/SofaScoreDataMail.php b/app/Mail/SofaScoreDataMail.php index 6e344679..308d5890 100644 --- a/app/Mail/SofaScoreDataMail.php +++ b/app/Mail/SofaScoreDataMail.php @@ -8,7 +8,6 @@ use Illuminate\Mail\Mailables\Attachment; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; use Illuminate\Queue\SerializesModels; -use App\Console\Commands\Grapper\Sofascore; class SofaScoreDataMail extends Mailable { @@ -17,13 +16,7 @@ class SofaScoreDataMail extends Mailable /** * Create a new message instance. */ - public function __construct(string $header, string $message) - { - $this->header = $header; - $this->message = $message; - $this->archive_name = Sofascore::$archive_name; - $this->zip_file = Sofascore::$storage . Sofascore::$archive_name; - } + public function __construct(public string $header, public string $table, public array $sendfiles) {} /** * Get the message envelope. @@ -43,7 +36,8 @@ class SofaScoreDataMail extends Mailable return new Content( markdown: 'mail.user.sofascore_data', with: [ - 'message' => $this->message, + 'message' => $this->header, + 'table' => $this->table, ], ); } @@ -52,13 +46,16 @@ class SofaScoreDataMail extends Mailable * Get the attachments for the message. * * @return array + * ->withMime('application/x-zip-compressed'); */ public function attachments(): array { - return [ - Attachment::fromPath($this->zip_file) - ->as($this->archive_name) - ->withMime('application/x-zip-compressed') - ]; + $attachments = []; + foreach ($this->sendfiles as $sendfile) { + $attachments[] = Attachment::fromPath($sendfile) + ->withMime('application/vnd.openxmlformats-officedocument.spreadsheetml.template'); + } + + return $attachments; } } diff --git a/resources/views/mail/user/sofascore_data.blade.php b/resources/views/mail/user/sofascore_data.blade.php index 6c070f1d..8e058a9f 100644 --- a/resources/views/mail/user/sofascore_data.blade.php +++ b/resources/views/mail/user/sofascore_data.blade.php @@ -1,3 +1,11 @@ - - {{ $message }} - \ No newline at end of file +@component('mail::message') +# {{ $message }} + +@component('mail::table') +| Liga | Event | Starttime | +|:------------- |:-------------| --------:| +{{ $table }} +@endcomponent + +@endcomponent + diff --git a/resources/views/vendor/mail/html/header.blade.php b/resources/views/vendor/mail/html/header.blade.php index aef92eb9..19ce69e0 100644 --- a/resources/views/vendor/mail/html/header.blade.php +++ b/resources/views/vendor/mail/html/header.blade.php @@ -1,22 +1,41 @@ - -
- - - - - - - - - - - - - - -
- {!! $slot !!} -
- - \ No newline at end of file + +
+ + + + + + + + + + + + + + +
+{!! $slot !!} +
+ + diff --git a/resources/views/vendor/mail/html/layout.blade.php b/resources/views/vendor/mail/html/layout.blade.php index 037efe3e..fa8dfe04 100644 --- a/resources/views/vendor/mail/html/layout.blade.php +++ b/resources/views/vendor/mail/html/layout.blade.php @@ -1,5 +1,7 @@ - + + {{ config('app.name') }} @@ -25,6 +27,7 @@ width: 100% !important; {!! $head ?? '' !!} + @@ -35,8 +38,10 @@ width: 100% !important; -