centralized grapper tournaments wi

This commit is contained in:
salam committed 2026-10-11 15:42:00 +02:00
1 parent 34701ecbff
commit db917bdc92
8 files changed
+379 -173

No files matched your search

+40 -15
View File
@@ -3,8 +3,11 @@
namespace App\Traits\Sofascore;
use App\Mail\SimpleMail;
use App\Models\SofaScoreEventGrapped;
use App\Models\SofaScoreTaskDay;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Mail;
@@ -37,6 +40,10 @@ trait GrappingSofascore
protected array $tournaments_requested = [];
protected array $grapped_files = [];
protected Collection $day_tournaments;
protected array $days = [];
public function handle(): void
@@ -116,8 +123,6 @@ trait GrappingSofascore
$this->task_id = 1;
$this->restart = 1;
$this->set_base_dir($folder);
$this->load_tournaments_requested($folder);
@@ -126,9 +131,14 @@ trait GrappingSofascore
switch ($restart) {
case 'restart':
$this->restart = 1;
SofaScoreEventGrapped::truncate();
break;
case 'clear':
$this->restart = 1;
SofaScoreEventGrapped::truncate();
$this->clear_folder($folder, 'all');
break;
}
@@ -136,37 +146,47 @@ trait GrappingSofascore
/**
* day 1
*/
$day = Carbon::now()->subDay()->format('Y-m-d');
$this->grap_tournaments_for_day($day);
$res = SofaScoreTaskDay::where('grapper_id', (int) $this->task_id)->where('day', $day)->first();
foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament);
if (! $res) {
$this->grapped_files = $this->get_tree($this->data_dir.'/'.$day);
$this->grap_tournaments_for_day($day);
foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament);
}
SofaScoreTaskDay::updateOrCreate(['grapper_id' => (int) $this->task_id, 'day' => $day], ['done' => 1]);
}
/**
* day 5
*/
$day = Carbon::now()->subDays(5)->format('Y-m-d');
$this->grap_tournaments_for_day($day);
$res = SofaScoreTaskDay::where('grapper_id', (int) $this->task_id)->where('day', $day)->first();
foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament);
if (! $res) {
$this->grapped_files = $this->get_tree($this->data_dir.'/'.$day);
$this->grap_tournaments_for_day($day);
foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament);
}
SofaScoreTaskDay::updateOrCreate(['grapper_id' => (int) $this->task_id, 'day' => $day], ['done' => 1]);
}
/**
* to excel day by day
*/
$this->import_to_excel($folder);
/**
* mail it
*/
$this->send($folder);
}
@@ -188,6 +208,8 @@ trait GrappingSofascore
foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament);
}
SofaScoreTaskDay::updateOrCreate(['grapper_id' => (int) $this->task_id, 'day' => $day], ['done' => 1]);
}
if ($this->debug) {
@@ -243,6 +265,8 @@ trait GrappingSofascore
foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament);
}
SofaScoreTaskDay::updateOrCreate(['grapper_id' => (int) $this->task_id, 'day' => $day], ['done' => 1]);
}
}
@@ -258,8 +282,9 @@ trait GrappingSofascore
$directories = File::directories($this->data_dir);
$arr = [];
foreach ($directories as $directory) {
$arr[] = substr(strrchr($directory, "/"), 1);
$arr[] = substr(strrchr($directory, '/'), 1);
}
return $arr;
}