wip grap ss tournament

This commit is contained in:
salam committed 2026-06-07 07:18:22 +02:00
1 parent d4dfb9748c
commit 292acb879e
31 files changed
+4025 -224

No files matched your search

+25 -9
View File
@@ -2,9 +2,12 @@
namespace App\Console\Commands\Grapper;
use App\Console\Commands\Grapper\Sportscore\Helper;
use App\Console\Commands\Grapper\Sofascore\Tournament;
use App\Console\Commands\Nuh;
use App\Models\Sport;
use App\Models\SofaScoreCategorie;
use App\Models\SofaScoreDayTournament;
use App\Models\SofaScoreTournament;
use App\Utilities\Notice;
class Sofascore
{
@@ -12,18 +15,31 @@ class Sofascore
public static $base_url = '';
public static $sport = [];
public static $sport = [1];
public static function switch()
{
self::$sport = Helper::map();
dd(self::$sport, Nuh::$options);
$debug = Nuh::$options['d'] ?? 0;
$truncat = Nuh::$options['t'] ?? 0;
$echo_data = Nuh::$options['e'] ?? 0;
if ($truncat) {
SofaScoreDayTournament::truncate();
SofaScoreTournament::truncate();
SofaScoreCategorie::truncate();
}
$sportmap = Sport::map('logi', 1, [Nuh::$options['sport_id']]);
if ($debug) {
Notice::note(Nuh::$options['sport'].' '.Nuh::$options['name'], 'b');
}
switch (Nuh::$options['name']) {
case 'TOURNAMENTS':
Tournament::load();
break;
default:
// code...
break;
}
}
}
@@ -0,0 +1,101 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Curl;
use App\Console\Commands\Nuh;
use App\Models\Country;
use App\Models\SofaScoreCategorie;
use App\Models\SofaScoreDay;
use App\Models\SofaScoreTournament;
use App\Models\Sport;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class Events
{
public static $auth_header = [];
public static $base_url = '';
public static $sport = [1];
public static function switch()
{
$debug = Nuh::$options['d'] ?? 0;
$sportmap = Sport::whereIn('id', self::$sport)->select('id', 'sofascore', 'ss_slug')->get();
$time_zone_offset = 0;
$years_back = 7;
$dates = Carbon::now()->subYears($years_back);
SofaScoreTournament::truncate();
SofaScoreCategorie::truncate();
foreach ($sportmap as $sport) {
while ($dates <= Carbon::now()) {
$day = $dates->format('Y-m-d');
SofaScoreDay::updateOrCreate(['day' => $day], [$sport->ss_slug => 1]);
$page = 1;
while ($page) {
$url = Nuh::$options['base_url']."api/v1/sport/$sport->ss_slug/scheduled-tournaments/$day/page/$page";
$data = Curl::load($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'];
/**
* CATEGORY
*/
$country_id = Country::where('name', $category['name'])->value('id');
$call = SofaScoreCategorie::updateOrCreate([
'id' => (int) $category['id'],
'country_id' => (int) $country_id,
'slug' => $category['slug'],
], [
'name' => $category['name'],
]);
/**
* TOURNAMENT
*/
$sofa_score_categorie_id = $call->id;
SofaScoreTournament::updateOrCreate([
'id' => (int) $tournament['id'],
'day' => $day,
], [
'sport_id' => (int) $sport->id,
'sofa_score_categorie_id' => (int) $sofa_score_categorie_id,
'name' => $tournament['name'],
'slug' => $tournament['slug'],
]);
}
}
Notice::note('All day grapped', 'g', 1);
}
}
}
}
@@ -1,38 +1,8 @@
<?php
namespace App\Console\Commands\Grapper\Sportscore;
namespace App\Console\Commands\Grapper\Sofascore;
class Helper
{
// football
// basketball
// tennis
// ice-hockey
// baseball
public static function map()
{
return [
1 => [
'name' => 'Soccer',
'slug' => 'football',
],
2 => [
'name' => 'Basketball',
'slug' => 'basketball',
],
4 => [
'name' => 'Ice Hockey',
'slug' => 'ice-hockey',
],
5 => [
'name' => 'Tennis',
'slug' => 'tennis',
],
64 => [
'name' => 'Baseball',
'slug' => 'baseball',
],
];
}
public static function map() {}
}
@@ -0,0 +1,159 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Curl;
use App\Console\Commands\Nuh;
use App\Models\Country;
use App\Models\SofaScoreCategorie;
use App\Models\SofaScoreDay;
use App\Models\SofaScoreDayTournament;
use App\Models\SofaScoreTournament;
use App\Models\Sport;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class Tournament
{
public static $auth_header = [];
public static $base_url = '';
public static $sport = [1];
public static function load()
{
$debug = Nuh::$options['d'] ?? 0;
$YEAR_GO_BACK = date('Y') - 5;
$sport_id = Nuh::$options['sport_id'];
$slug = Sport::where('id', $sport_id)->value('ss_slug');
$dates = Carbon::now();
while ($dates >= Carbon::now()->subYears($YEAR_GO_BACK)) {
$tournaments_counter = 0;
$day = $dates->format('Y-m-d');
Notice::note('sport: '.Nuh::$options['sport'].' day: '.$day, 'p');
/**
* grap only one time/sport check
*/
if (! SofaScoreDay::where('day', $day)->where($slug, 1)->first()) {
SofaScoreDay::updateOrCreate(['day' => $day], [$slug => 1]);
$page = 1;
while ($page) {
$url = Nuh::$options['base_url']."api/v1/sport/$slug/scheduled-tournaments/$day/page/$page";
$rand = rand(1000000, 2000000);
if ($debug) {
Notice::note("Sleep $rand msec", 'g');
}
usleep($rand);
$data = Curl::load($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',
];
$replace = [
'',
'Bosnia Herzegovina',
'Czech Republic',
'Congo DR',
'Holland',
'North America',
'Bonaire, Sint Eustatius and Saba',
'Sao Tome e Principe',
'Cape Verde Islands',
'Macau',
];
$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
$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,
]);
}
Notice::note("tournaments: $tournaments_counter", 'p');
}
}
$dates->subDay();
}
}
}