wip fix
This commit is contained in:
1 parent
9bcd4432c6
commit
6f92f9e1d5
1209 files changed
+220940
No files matched your search
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits\Sofascore;
|
||||
|
||||
use App\Models\SofaScoreCategory;
|
||||
use App\Models\SofaScoreDayTournament;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use App\Services\CloudflareSolverService;
|
||||
use App\Utilities\Notice;
|
||||
|
||||
trait GrappingTournaments
|
||||
{
|
||||
/**
|
||||
* Summary of grap_tournaments_for_day
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function grap_tournaments_for_day(string $day)
|
||||
{
|
||||
$sport_id = 1;
|
||||
|
||||
$has = SofaScoreDayTournament::where('day', $day)->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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user