wip
This commit is contained in:
1 parent
9e6f7e1c06
commit
88205b7aa1
8 files changed
+133
-168
No files matched your search
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace App\Console\Commands\Grapper;
|
||||
|
||||
use App\Console\Commands\Grapper\Sofascore\DaysTournament;
|
||||
use App\Console\Commands\Grapper\Sofascore\Grapper;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\Strings;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\TaskConfig;
|
||||
use App\Console\Commands\Grapper\Sofascore\PlayerPerSeason;
|
||||
use App\Console\Commands\Grapper\Sofascore\SendMail;
|
||||
use App\Console\Commands\Grapper\Sofascore\SettingsToLocal;
|
||||
@@ -35,20 +33,16 @@ class Sofascore
|
||||
break;
|
||||
|
||||
case 3:
|
||||
DaysTournament::run();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
self::setStorage();
|
||||
Grapper::load();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
case 4:
|
||||
self::setStorage();
|
||||
ZipFolder::create(self::$storage);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
case 5:
|
||||
self::setStorage();
|
||||
SendMail::run();
|
||||
break;
|
||||
@@ -63,7 +57,5 @@ class Sofascore
|
||||
$task = Nuh::$options['task'];
|
||||
|
||||
self::$storage = storage_path('sofascore_data') . '/' . Strings::clean(SofaScoreTask::where('id', $task)->value('name'));
|
||||
|
||||
dd(self::$storage);
|
||||
}
|
||||
}
|
||||
@@ -24,153 +24,150 @@ class DaysTournament
|
||||
* Spa La Liga 15-08-2025 - 24-05-2026
|
||||
* Fra Liggue 15-08-2025 - 17-05-2026
|
||||
*/
|
||||
public static function run()
|
||||
public static function get(array $d)
|
||||
{
|
||||
$debug = Nuh::$options['d'] ?? 0;
|
||||
|
||||
$days = LoadDays::load();
|
||||
|
||||
$tournaments_counter = 0;
|
||||
|
||||
foreach ($days as $d) {
|
||||
$sport_id = $d['sport_id'];
|
||||
|
||||
$sport_id = $d['sport_id'];
|
||||
$day = $d['day'];
|
||||
$slug = $d['slug'];
|
||||
$day = $d['day'];
|
||||
|
||||
$has = SofaScoreDayTournament::where('day', $day)->where('sport_id', $sport_id)->first();
|
||||
$slug = $d['slug'];
|
||||
|
||||
if ($has) {
|
||||
if ($debug) {
|
||||
Notice::note("All tournament for $day have been allready grapped", 'g');
|
||||
}
|
||||
} else {
|
||||
$has = SofaScoreDayTournament::where('day', $day)->where('sport_id', $sport_id)->first();
|
||||
|
||||
if ($debug) {
|
||||
Notice::note("$day\ngrappig", 'g');
|
||||
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 = Nuh::$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;
|
||||
}
|
||||
|
||||
$page = 1;
|
||||
foreach ($data['scheduled'] as $row) {
|
||||
|
||||
while ($page) {
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/sport/$slug/scheduled-tournaments/$day/page/$page";
|
||||
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
if ($data['hasNextPage']) {
|
||||
$page++;
|
||||
if (isset($row['tournament']['uniqueTournament'])) {
|
||||
$tournament = $row['tournament']['uniqueTournament'];
|
||||
} else {
|
||||
$page = false;
|
||||
$tournament = $row['tournament'];
|
||||
}
|
||||
|
||||
foreach ($data['scheduled'] as $row) {
|
||||
$category = $tournament['category'];
|
||||
|
||||
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_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;
|
||||
}
|
||||
if ($sport_id == 5) {
|
||||
$country_id = 470;
|
||||
} else {
|
||||
|
||||
/**
|
||||
* TOURNAMENT
|
||||
* CATEGORY
|
||||
*/
|
||||
SofaScoreTournament::updateOrCreate([
|
||||
'sport_id' => (int) $sport_id,
|
||||
'tournament_id' => (int) $tournament['id'],
|
||||
'sofa_score_categorie_id' => (int) $sofa_score_categorie_id,
|
||||
$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_categorie_id = 10000000;
|
||||
} else {
|
||||
$call = SofaScoreCategorie::updateOrCreate([
|
||||
'id' => (int) $category['id'],
|
||||
'country_id' => (int) $country_id,
|
||||
'slug' => $category['slug'],
|
||||
], [
|
||||
'name' => $tournament['name'],
|
||||
'slug' => $tournament['slug'],
|
||||
'name' => $category['name'],
|
||||
]);
|
||||
$tournaments_counter++;
|
||||
|
||||
$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++;
|
||||
|
||||
// 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,10 @@ use Illuminate\Support\Facades\File;
|
||||
|
||||
class Grapper
|
||||
{
|
||||
|
||||
/**
|
||||
* last 3 days = task 1
|
||||
*
|
||||
* nuh --d --f 67 --fun=6 --task=1
|
||||
*/
|
||||
|
||||
public static function load()
|
||||
{
|
||||
$debug = Nuh::$options['d'] ?? 0;
|
||||
|
||||
$force = Nuh::$options['f'] ?? 0;
|
||||
|
||||
$task_id = Nuh::$options['task'] ?? 0;
|
||||
|
||||
$days = LoadDays::load();
|
||||
@@ -47,15 +38,18 @@ class Grapper
|
||||
if ($debug)
|
||||
Notice::note('Truncate SofaScoreEventGrapped', 'b');
|
||||
|
||||
SofaScoreEventGrapped::query()->truncate();
|
||||
SofaScoreEventGrapped::where('grapper_id', $task_id)->delete();
|
||||
|
||||
foreach ($active_tournaments as $tournament) {
|
||||
foreach ($days as $d) {
|
||||
|
||||
if ($debug) {
|
||||
Notice::note($tournament->tournament->name, 'bg');
|
||||
}
|
||||
DaysTournament::get($d);
|
||||
|
||||
foreach ($active_tournaments as $tournament) {
|
||||
|
||||
if ($debug) {
|
||||
Notice::note($tournament->tournament->name, 'bg');
|
||||
}
|
||||
|
||||
foreach ($days as $d) {
|
||||
|
||||
$day = $d['day'];
|
||||
|
||||
@@ -95,12 +89,12 @@ class Grapper
|
||||
}
|
||||
|
||||
$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();
|
||||
$grapped->in_current_grapper = true;
|
||||
|
||||
$folder = Sofascore::$storage . '/' . $day . '/' . $event['tournament']['slug'] . '/' . $event['slug'];
|
||||
|
||||
|
||||
@@ -37,18 +37,6 @@ class LoadDays
|
||||
'sport_id' => $task->sport_id,
|
||||
'run_repeatedly' => $task->run_repeatedly,
|
||||
];
|
||||
// $dates[] = [
|
||||
// 'day' => Carbon::now()->subDays(2)->format('Y-m-d'),
|
||||
// 'slug' => $task->sport->ss_slug,
|
||||
// 'sport_id' => $task->sport_id,
|
||||
// 'run_repeatedly' => $task->run_repeatedly,
|
||||
// ];
|
||||
// $dates[] = [
|
||||
// 'day' => Carbon::now()->subDays(3)->format('Y-m-d'),
|
||||
// 'slug' => $task->sport->ss_slug,
|
||||
// 'sport_id' => $task->sport_id,
|
||||
// 'run_repeatedly' => $task->run_repeatedly,
|
||||
// ];
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
-2
@@ -2,11 +2,9 @@
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\Tables;
|
||||
|
||||
use App\Models\SofaScoreTask;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class SofaScoreTasksTable
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Utilities;
|
||||
|
||||
use App\Console\Commands\Grapper\Sofascore;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use ZipArchive;
|
||||
|
||||
Reference in new issue
Block a user