debug) { Notice::note('⚽ tournaments for day '.$day); Notice::note('⚽ close all vpn'); } // exec('killall ssh'); if ($this->debug) { Notice::note('⚽ open vpn'); } $this->pid = exec('ssh -f -N -L 13306:127.0.0.1:3306 -p 58371 root@162.55.242.190 > /dev/null 2>&1 & echo $!'); /** * SofaScoreDayTournament */ if ($this->debug) { Notice::note('get tournaments; pid: '.$this->pid, 'g'); } $this->day_tournaments = SofaScoreDayTournament::where('day', $day)->get(); if (! $this->restart && $this->day_tournaments->count() > 0) { if ($this->debug) { Notice::note("$day Tournaments allready grapped", 'bb'); } if ($this->debug) { Notice::note('⚽ close all vpn'); } // exec('killall ssh'); exec("kill $this->pid"); return; } else { $page = 1; $tournaments_counter = 0; $slug = 'football'; while ($page) { // $data = $this->curl($url); $this->grapper_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'); } $this->day_tournaments = SofaScoreDayTournament::where('day', $day)->get(); if ($this->debug) { Notice::note('⚽ close all vpn'); } // exec('killall ssh'); exec("kill $this->pid"); } } }