This commit is contained in:
salam committed 2026-10-01 15:10:40 +02:00
1 parent 78db21c71c
commit e1f3b728a9
9 files changed
+252 -203

No files matched your search

+45 -11
View File
@@ -4,6 +4,7 @@ namespace App\Traits\Sofascore;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\File;
use function Laravel\Prompts\select;
use function Laravel\Prompts\text;
@@ -62,9 +63,7 @@ trait GrapSofascore
switch ($grapperSelected) {
case 'daily':
$this->task_id = 1;
$this->days_back = (int) $this->select_day();
$this->run_daily($grapperSelected);
break;
@@ -76,16 +75,19 @@ trait GrapSofascore
case 'settings':
$this->settings_to_local();
break;
case 'excel':
$folder = $this->select_folder();
$this->import_to_excel($folder);
break;
case 'mail':
$folder = $this->select_folder();
$this->send($folder);
break;
case 'clear':
$folder = $this->select_folder();
@@ -117,7 +119,16 @@ trait GrapSofascore
$this->load_tournaments_requested($folder);
$this->clear_folder($folder, 'all');
$restart = $this->ask_restart();
switch ($restart) {
case 'restart':
$this->restart = 1;
break;
case 'clear':
$this->restart = 1;
$this->clear_folder($folder, 'all');
break;
}
/**
* day 1
@@ -196,12 +207,18 @@ trait GrapSofascore
$this->set_base_dir($folder);
$restart = $this->ask_restart();
if ($restart == 'yes') {
$this->restart = 1;
$this->clear_folder($folder, 'all');
switch ($restart) {
case 'restart':
$this->restart = 1;
break;
case 'clear':
$this->restart = 1;
$this->clear_folder($folder, 'all');
break;
}
$day_done = $this->days_done();
$this->load_tournaments_requested($folder);
$this->load_days($folder);
@@ -213,10 +230,16 @@ trait GrapSofascore
Notice::note("$key/$count", 'br');
}
$this->grap_tournaments_for_day($day);
if (in_array($day, $day_done)) {
if ($this->debug) {
Notice::note("$day already in folder", 'br');
}
} else {
$this->grap_tournaments_for_day($day);
foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament);
foreach ($this->tournaments_requested as $tournament) {
$this->get_event($day, $tournament);
}
}
}
@@ -225,6 +248,16 @@ trait GrapSofascore
Notice::note('Done', 'g');
}
protected function days_done(): array
{
$directories = File::directories($this->data_dir);
$arr = [];
foreach ($directories as $directory) {
$arr[] = substr(strrchr($directory, "/"), 1);
}
return $arr;
}
/**
* Summary of select_grapper
*/
@@ -279,8 +312,9 @@ trait GrapSofascore
label: 'Restart Grapper?',
default: 'no',
options: [
'yes' => 'Yes',
'no' => 'No',
'restart' => 'Restart',
'clear' => 'Clear folder and restart',
]
);
}
+12 -12
View File
@@ -19,15 +19,15 @@ trait GrapperEvent
if ($res) {
if ($this->debug) {
Notice::note("$day - ".$tournament['tournament']['name'].' - '.$tournament['sofa_score_tournament_id'], 'b');
Notice::note("$day - " . $tournament['tournament']['name'] . ' - ' . $tournament['sofa_score_tournament_id'], 'bb');
}
$this->sleep(1);
$url = $this->base_url.'api/v1/unique-tournament/'.$tournament['sofa_score_tournament_id']."/scheduled-events/$day";
$url = $this->base_url . 'api/v1/unique-tournament/' . $tournament['sofa_score_tournament_id'] . "/scheduled-events/$day";
if ($this->debug) {
Notice::note($url, 'bb');
Notice::note($url, 'b');
}
$this->sleep(1);
@@ -40,17 +40,17 @@ trait GrapperEvent
foreach ($data['events'] as $event) {
if (! $this->force && SofaScoreEventGrapped::where('grapper_id', $this->task_id)->where('id', (int) $event['id'])->exists()) {
if (! $this->restart && SofaScoreEventGrapped::where('grapper_id', $this->task_id)->where('id', (int) $event['id'])->exists()) {
if ($this->debug) {
Notice::note('DB - Allready grapped at '.$day.' - '.$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'b');
Notice::note('DB - Allready grapped at ' . $day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'b');
}
} else {
if ($this->debug) {
Notice::note("$day - ".$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'g');
Notice::note("$day - " . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'g');
}
$folder = strtolower("$this->data_dir/$day/$day-".$event['tournament']['category']['slug'].'-'.$event['tournament']['slug'].'/'.$event['slug']);
$folder = strtolower("$this->data_dir/$day/$day-" . $event['tournament']['category']['slug'] . '-' . $event['tournament']['slug'] . '/' . $event['slug']);
File::makeDirectory($folder, 0775, true, true);
@@ -66,7 +66,7 @@ trait GrapperEvent
$event_id = $event['id'];
$url = $this->base_url."api/v1/event/$event_id/statistics";
$url = $this->base_url . "api/v1/event/$event_id/statistics";
if ($this->debug) {
Notice::note($url, 'b');
@@ -84,7 +84,7 @@ trait GrapperEvent
* EVENT lineups
*********************************/
$url = $this->base_url."api/v1/event/$event_id/lineups";
$url = $this->base_url . "api/v1/event/$event_id/lineups";
if ($this->debug) {
Notice::note($url, 'b');
@@ -102,7 +102,7 @@ trait GrapperEvent
* EVENT odds
*********************************/
$url = $this->base_url."api/v1/event/$event_id/odds/1/all";
$url = $this->base_url . "api/v1/event/$event_id/odds/1/all";
if ($this->debug) {
Notice::note($url, 'b');
@@ -120,7 +120,7 @@ trait GrapperEvent
* EVENT incidents
*********************************/
$url = $this->base_url."api/v1/event/$event_id/incidents";
$url = $this->base_url . "api/v1/event/$event_id/incidents";
if ($this->debug) {
Notice::note($url, 'b');
@@ -142,7 +142,7 @@ trait GrapperEvent
'grapper_id' => $this->task_id,
'day' => $day,
'liga' => $event['tournament']['name'],
'name' => $event['homeTeam']['name'].' vs '.$event['awayTeam']['name'],
'name' => $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'],
'url' => $url,
'starttime' => $starttime->toDateTimeString(),
]);
+23 -23
View File
@@ -73,19 +73,19 @@ trait GrappingHelper
break;
}
if ($this->restart) {
SofaScoreEventGrapped::where('grapper_id', $this->task_id)->delete();
// if ($this->restart) {
// SofaScoreEventGrapped::where('grapper_id', $this->task_id)->delete();
foreach ($this->days as $day) {
// if restarting find position
SofaScoreTaskDay::where('grapper_id', 1)
->where('day', $day)
->update(['done' => 0]);
}
if ($this->debug) {
Notice::note('Grapper restarted', 'r', 1);
}
}
// foreach ($this->days as $day) {
// // if restarting find position
// SofaScoreTaskDay::where('grapper_id', 1)
// ->where('day', $day)
// ->update(['done' => 0]);
// }
// if ($this->debug) {
// Notice::note('Grapper restarted', 'r', 1);
// }
// }
$this->days = array_unique($this->days, SORT_REGULAR);
}
@@ -97,16 +97,16 @@ trait GrappingHelper
{
switch ($grapperSelected) {
case 'daily':
$this->data_dir = storage_path($this->base_dir).'/daily';
$this->data_dir = storage_path($this->base_dir) . '/daily';
break;
case 'range':
$this->data_dir = storage_path($this->base_dir).'/range';
$this->data_dir = storage_path($this->base_dir) . '/range';
break;
case 'rose':
$this->data_dir = storage_path($this->base_dir).'/rose';
$this->data_dir = storage_path($this->base_dir) . '/rose';
break;
case 'player':
$this->data_dir = storage_path($this->base_dir).'/player';
$this->data_dir = storage_path($this->base_dir) . '/player';
break;
case 'excel':
case 'mail':
@@ -231,7 +231,7 @@ trait GrappingHelper
if (! $this->force && $has) {
if ($this->debug) {
Notice::note("tournaments $day for ".strtoupper($slug).' allready grapped', 'bb');
Notice::note("tournaments $day for " . strtoupper($slug) . ' allready grapped', 'bb');
}
} else {
@@ -246,7 +246,7 @@ trait GrappingHelper
$this->sleep();
$url = $this->base_url."api/v1/sport/$slug/scheduled-tournaments/$day/page/$page";
$url = $this->base_url . "api/v1/sport/$slug/scheduled-tournaments/$day/page/$page";
$cloudflareService = new CloudflareSolverService;
@@ -372,7 +372,7 @@ trait GrappingHelper
{
$files = scandir($dir);
foreach ($files as $value) {
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
if (! is_dir($path)) {
$results[] = $path;
} elseif ($value != '.' && $value != '..') {
@@ -395,7 +395,7 @@ trait GrappingHelper
protected function clear_folder(string $folder, $what = '')
{
$mainFolder = storage_path($this->base_dir.'/'.$folder);
$mainFolder = storage_path($this->base_dir . '/' . $folder);
if (! $what) {
$what = $this->select_what_delete();
@@ -426,8 +426,8 @@ trait GrappingHelper
$tasks = StatistikoImport::pluck('file_name')->toArray();
collect(Storage::disk('public')->allFiles('statistiko'))
->reject(fn (string $file) => $file === '.gitignore')
->reject(fn (string $file) => in_array($file, $tasks))
->each(fn ($file) => Storage::disk('public')->delete($file));
->reject(fn(string $file) => $file === '.gitignore')
->reject(fn(string $file) => in_array($file, $tasks))
->each(fn($file) => Storage::disk('public')->delete($file));
}
}
+63 -52
View File
@@ -19,66 +19,77 @@ trait GrappingToExcel
ini_set('memory_limit', -1);
if ($this->debug) {
Notice::note("Import to Excel", 'bb');
Notice::note("Import $folder to Excel", 'bb');
}
$directories = File::directories($this->data_dir . '/' . $folder);
foreach ($directories as $directory) {
$day = substr(strrchr($directory, "/"), 1);
$this->titel = ucfirst($folder) . '-' . $day;
$files = $this->get_tree($directory);
// only json max 2000
$files = array_chunk($this->filter($files), $this->max);
foreach ($files as $key => $value) {
$has = count($value);
if (! $key && $has < $this->max) {
$count_from = 1;
$count_to = $has;
} elseif (! $key) {
$count_from = 1;
$key++;
$count_to = $key * $this->max;
} elseif ($has == $this->max) {
$count_from = $key * $this->max + 1;
$key++;
$count_to = $key * $this->max;
} else {
$count_from = $key * $this->max + 1;
$count_to = $key * $this->max + $has;
switch ($folder) {
case 'daily':
$directories = File::directories($this->data_dir);
foreach ($directories as $directory) {
$day = substr(strrchr($directory, "/"), 1);
$this->titel = ucfirst($folder) . '-' . $day;
$this->make_file($this->data_dir . '/' . $day);
}
break;
$spreadsheet = new Spreadsheet;
$spreadsheet->getProperties()->setTitle($this->titel . '-' . $count_from . '-' . $count_to);
$activeWorksheet = $spreadsheet->getActiveSheet();
case 'range':
$task = SofaScoreTask::with('sport')->where('id', 3)->first();
$this->titel = ucfirst($folder) . '-' . $this->clean_string($task->name);
$this->make_file($this->data_dir);
break;
}
}
$column = 1;
foreach ($value as $file) {
$data = file_get_contents($file);
$data = json_decode($data, true);
$json_string = json_encode($data, JSON_PRETTY_PRINT);
protected function make_file(string $directory)
{
$files = $this->get_tree($directory);
$arr = explode(PHP_EOL, $json_string);
$row = 0;
foreach ($arr as $string) {
$row++;
$replacedString = preg_replace('/\\\\u([0-9abcdef]{4})/', '&#x$1;', $string);
$utf8string = mb_convert_encoding($replacedString, 'UTF-8', 'HTML-ENTITIES');
$activeWorksheet->setCellValue([$column, $row], $utf8string);
}
$column++;
}
// only json max 2000
$files = array_chunk($this->filter($files), $this->max);
$spreadsheet->setActiveSheetIndex(0);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save("$this->data_dir/$this->titel-$count_from-$count_to.xlsx");
foreach ($files as $key => $value) {
$has = count($value);
if (! $key && $has < $this->max) {
$count_from = 1;
$count_to = $has;
} elseif (! $key) {
$count_from = 1;
$key++;
$count_to = $key * $this->max;
} elseif ($has == $this->max) {
$count_from = $key * $this->max + 1;
$key++;
$count_to = $key * $this->max;
} else {
$count_from = $key * $this->max + 1;
$count_to = $key * $this->max + $has;
}
$spreadsheet = new Spreadsheet;
$spreadsheet->getProperties()->setTitle($this->titel . '-' . $count_from . '-' . $count_to);
$activeWorksheet = $spreadsheet->getActiveSheet();
$column = 1;
foreach ($value as $file) {
$data = file_get_contents($file);
$data = json_decode($data, true);
$json_string = json_encode($data, JSON_PRETTY_PRINT);
$arr = explode(PHP_EOL, $json_string);
$row = 0;
foreach ($arr as $string) {
$row++;
$replacedString = preg_replace('/\\\\u([0-9abcdef]{4})/', '&#x$1;', $string);
$utf8string = mb_convert_encoding($replacedString, 'UTF-8', 'HTML-ENTITIES');
$activeWorksheet->setCellValue([$column, $row], $utf8string);
}
$column++;
}
$spreadsheet->setActiveSheetIndex(0);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save("$this->data_dir/$this->titel-$count_from-$count_to.xlsx");
}
}