diff --git a/app/Console/Commands/Grapper.php b/app/Console/Commands/Grapper.php index e15e9139..13d3ae17 100644 --- a/app/Console/Commands/Grapper.php +++ b/app/Console/Commands/Grapper.php @@ -2,12 +2,12 @@ namespace App\Console\Commands; -use App\Traits\Sofascore\GrapSofascore; +use App\Traits\Sofascore\GrappingSofascore; use Illuminate\Console\Command; class Grapper extends Command { - use GrapSofascore; + use GrappingSofascore; protected $signature = 'grp:sofa {--d} {--r} {--f}'; diff --git a/app/Console/Commands/GrapperDaily.php b/app/Console/Commands/GrapperDaily.php index 5a73cbd7..a3d1d99a 100644 --- a/app/Console/Commands/GrapperDaily.php +++ b/app/Console/Commands/GrapperDaily.php @@ -2,12 +2,12 @@ namespace App\Console\Commands; -use App\Traits\Sofascore\GrapSofascore; +use App\Traits\Sofascore\GrappingSofascore; use Illuminate\Console\Command; class GrapperDaily extends Command { - use GrapSofascore; + use GrappingSofascore; protected $signature = 'grp:daily {--d} {--r} {--f}'; diff --git a/app/Services/CloudflareSolverService.php b/app/Services/CloudflareSolverService.php index 58192622..4c432ea7 100644 --- a/app/Services/CloudflareSolverService.php +++ b/app/Services/CloudflareSolverService.php @@ -16,18 +16,10 @@ class CloudflareSolverService * Holt die Daten und gibt das extrahierte JSON als PHP-Array zurück. * Wenn etwas schiefgeht, wird null zurückgegeben. */ - public function getJsonFromUrl(string $targetUrl, int $debug): ?array + public function getJsonFromUrl(string $targetUrl): ?array { - /** - * set in .env - * FLARESOLVERR_IP_DOCKER="http://192.168.178.187:8191/v1" - */ - $this->solverUrl = env('FLARESOLVERR_IP_DOCKER', 'http://flaresolverr:8191/v1'); - - if ($debug) { - Notice::note($this->solverUrl, 'bb'); - } + $this->solverUrl = config('services.flaresolverr.id_docker'); try { $response = Http::withHeaders([ diff --git a/app/Traits/Sofascore/GrapperEvent.php b/app/Traits/Sofascore/GrappingEvent.php similarity index 94% rename from app/Traits/Sofascore/GrapperEvent.php rename to app/Traits/Sofascore/GrappingEvent.php index 06460dbb..f61a86f2 100644 --- a/app/Traits/Sofascore/GrapperEvent.php +++ b/app/Traits/Sofascore/GrappingEvent.php @@ -10,7 +10,7 @@ use App\Utilities\Notice; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\File; -trait GrapperEvent +trait GrappingEvent { protected function get_event(string $day, array $tournament) { @@ -22,19 +22,17 @@ trait GrapperEvent Notice::note("$day - " . $tournament['tournament']['name'] . ' - ' . $tournament['sofa_score_tournament_id'], 'bb'); } - $this->sleep(1); - $url = $this->base_url . 'api/v1/unique-tournament/' . $tournament['sofa_score_tournament_id'] . "/scheduled-events/$day"; if ($this->debug) { - Notice::note($url, 'b'); + Notice::note($url, 'p'); } - $this->sleep(2); + $this->sleep(1); $cloudflareService = new CloudflareSolverService; - $data = $cloudflareService->getJsonFromUrl($url, $this->debug); + $data = $cloudflareService->getJsonFromUrl($url); if (isset($data['events'])) { @@ -74,7 +72,7 @@ trait GrapperEvent $this->sleep(); - $data = $cloudflareService->getJsonFromUrl($url, $this->debug); + $data = $cloudflareService->getJsonFromUrl($url); $data['id'] = $event_id; @@ -92,7 +90,7 @@ trait GrapperEvent $this->sleep(); - $data = $cloudflareService->getJsonFromUrl($url, $this->debug); + $data = $cloudflareService->getJsonFromUrl($url); $data['id'] = $event_id; @@ -110,7 +108,7 @@ trait GrapperEvent $this->sleep(); - $data = $cloudflareService->getJsonFromUrl($url, $this->debug); + $data = $cloudflareService->getJsonFromUrl($url); $data['id'] = $event_id; @@ -128,7 +126,7 @@ trait GrapperEvent $this->sleep(); - $data = $cloudflareService->getJsonFromUrl($url, $this->debug); + $data = $cloudflareService->getJsonFromUrl($url); $data['id'] = $event_id; @@ -149,6 +147,10 @@ trait GrapperEvent } } } + } else { + if ($this->debug) { + Notice::note($day . ' - ' . $tournament['tournament']['name'] . " no events", 'y'); + } } SofaScoreTaskDay::updateOrCreate([ diff --git a/app/Traits/Sofascore/GrappingHelper.php b/app/Traits/Sofascore/GrappingHelper.php index fc4213ac..576ff861 100644 --- a/app/Traits/Sofascore/GrappingHelper.php +++ b/app/Traits/Sofascore/GrappingHelper.php @@ -215,156 +215,6 @@ trait GrappingHelper } } - /** - * Summary of grap_tournaments_for_day - * - * @return void - */ - protected function grap_tournaments_for_day(string $day) - { - $tournaments_counter = 0; - $sport_id = 1; - - $has = SofaScoreDayTournament::where('day', $day)->first(); - - $slug = 'football'; - - if (! $this->force && $has) { - if ($this->debug) { - Notice::note("$day tournaments allready grapped", 'br'); - } - } else { - - if ($this->debug) { - Notice::note("$day tournaments loaded", 'bb'); - } - - $page = 1; - - while ($page) { - // $data = $this->curl($url); - - $this->sleep(); - - $url = $this->base_url . "api/v1/sport/$slug/scheduled-tournaments/$day/page/$page"; - - $cloudflareService = new CloudflareSolverService; - - $data = $cloudflareService->getJsonFromUrl($url, $this->debug); - - if ($data['hasNextPage']) { - $page++; - } else { - $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'); - } - - 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; - } - - /** - * 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++; - - // if ($debug) { - // Notice::note('tournament: ' . $tournament['name'], 'p'); - // } - - /** - * DAY TOURNAMENT - */ - SofaScoreDayTournament::updateOrCreate([ - 'tournament_id' => (int) $tournament['id'], - 'sport_id' => (int) $sport_id, - 'day' => $day, - ]); - } - - if ($this->debug) { - Notice::note("tournaments: $tournaments_counter", 'p'); - } - } - } - } - protected function get_tree(string $dir, &$results = []) { $files = scandir($dir); diff --git a/app/Traits/Sofascore/GrapSofascore.php b/app/Traits/Sofascore/GrappingSofascore.php similarity index 90% rename from app/Traits/Sofascore/GrapSofascore.php rename to app/Traits/Sofascore/GrappingSofascore.php index 960041e2..ef678e10 100644 --- a/app/Traits/Sofascore/GrapSofascore.php +++ b/app/Traits/Sofascore/GrappingSofascore.php @@ -2,19 +2,22 @@ namespace App\Traits\Sofascore; +use App\Mail\SimpleMail; use App\Utilities\Notice; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Mail; use function Laravel\Prompts\select; use function Laravel\Prompts\text; -trait GrapSofascore +trait GrappingSofascore { - use GrapperEvent; + use GrappingEvent; use GrappingHelper; use GrappingMail; use GrappingToExcel; + use GrappingTournaments; protected int $debug; @@ -134,25 +137,25 @@ trait GrapSofascore * day 1 */ - $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); + // } /** * day 5 */ - $day = Carbon::now()->subDays(5)->format('Y-m-d'); + // $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); + // } /** * to excel day by day @@ -232,7 +235,7 @@ trait GrapSofascore if (in_array($day, $day_done)) { if ($this->debug) { - Notice::note("$day already in folder", 'br'); + Notice::note("$day Events allready grapped", 'br'); } } else { $this->grap_tournaments_for_day($day); @@ -246,6 +249,8 @@ trait GrapSofascore $this->import_to_excel($folder); Notice::note('Done', 'g'); + + Mail::to('hermann.telser@gmail.com')->send(new SimpleMail('STATISTIKO', 'Grapping compleated')); } protected function days_done(): array diff --git a/app/Traits/Sofascore/GrappingTournaments.php b/app/Traits/Sofascore/GrappingTournaments.php new file mode 100644 index 00000000..bdf28c64 --- /dev/null +++ b/app/Traits/Sofascore/GrappingTournaments.php @@ -0,0 +1,162 @@ +first(); + + $slug = 'football'; + + if (! $this->force && $has) { + if ($this->debug) { + Notice::note("$day Tournaments allready grapped", 'bb'); + } + } else { + + $page = 1; + $tournaments_counter = 0; + + while ($page) { + // $data = $this->curl($url); + + $this->sleep(); + + $url = $this->base_url . "api/v1/sport/$slug/scheduled-tournaments/$day/page/$page"; + + $cloudflareService = new CloudflareSolverService; + + $data = $cloudflareService->getJsonFromUrl($url); + + if ($data['hasNextPage']) { + $page++; + } else { + $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'); + } + + 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; + } + + /** + * 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++; + + // if ($debug) { + // Notice::note('tournament: ' . $tournament['name'], 'p'); + // } + + /** + * DAY TOURNAMENT + */ + SofaScoreDayTournament::updateOrCreate([ + 'tournament_id' => (int) $tournament['id'], + 'sport_id' => (int) $sport_id, + 'day' => $day, + ]); + } + + if ($this->debug) { + Notice::note("Tournaments: $tournaments_counter", 'p'); + } + } + + if ($this->debug) { + Notice::note("$day Tournaments loaded", 'bb'); + } + } + } +} diff --git a/config/services.php b/config/services.php index 11a68f46..b97ace6c 100644 --- a/config/services.php +++ b/config/services.php @@ -14,6 +14,8 @@ return [ | */ + + 'postmark' => [ 'token' => env('POSTMARK_TOKEN'), ], @@ -36,7 +38,8 @@ return [ ], 'flaresolverr' => [ - 'url' => env('FLARESOLVERR_URL', '192.168.178'), + 'url' => env('FLARESOLVERR_URL'), + 'id_docker' => env('FLARESOLVERR_IP_DOCKER'), ], ]; diff --git a/resources/views/mail/simple.blade.php b/resources/views/mail/simple.blade.php index c8d0b5f2..65f19877 100644 --- a/resources/views/mail/simple.blade.php +++ b/resources/views/mail/simple.blade.php @@ -8,7 +8,7 @@
{{ $body }}
-Vielen Dank!
+All is good!