move all to ss IDs

This commit is contained in:
salam committed 2026-08-01 11:42:47 +02:00
1 parent 09bf62c525
commit df0a2a9de0
24 files changed
+527 -101

No files matched your search

+23 -13
View File
@@ -24,7 +24,7 @@ class Sofascore
{
public static string $storage;
public static string $archive_name;
public static string $zipfile;
public static string $excel_name;
@@ -90,30 +90,40 @@ class Sofascore
public static function setStorage()
{
$task = Nuh::$options['task'];
$debug = Nuh::$options['d'];
self::$storage = storage_path('sofascore_data') . '/';
// for grapper to start with
$sofascore_data = storage_path('sofascore_data') . '/';
$task = SofaScoreTask::where('id', $task)->first();
if (!$task) {
Notice::note("No SofaScoreTask " . Nuh::$options['task'], 'r', 1);
}
$storage_name = Strings::clean($task->name);
$storage_name = Strings::clean(SofaScoreTask::where('id', $task)->value('name')) . '/';
switch ($task) {
switch ($task->id) {
case 1:
self::$archive_name = Carbon::now()->subDays(3)->format('Y-m-d') . '.zip';
self::$storage .= $storage_name . Carbon::now()->subDays(3)->format('Y-m-d');
self::$storage = $sofascore_data . $storage_name . '/' . Carbon::now()->subDays(3)->format('Y-m-d');
self::$zipfile = $sofascore_data . $storage_name . '/' . Carbon::now()->subDays(3)->format('Y-m-d') . '.zip';
break;
case 2:
self::$storage = $sofascore_data . $storage_name . '/' . $task->day_from;
self::$zipfile = $sofascore_data . $storage_name . '/' . $task->day_from . '.zip';
break;
case 3:
self::$archive_name = $storage_name . '.zip';
self::$storage .= $storage_name;
self::$storage = $sofascore_data . $storage_name . '-' . $task->day_from . '-' . $task->day_to;
self::$zipfile = $sofascore_data . $storage_name . '-' . $task->day_from . '-' . $task->day_to . '.zip';
break;
case 4:
self::$archive_name = 'rosa-' . Carbon::now()->format('Y-m-d') . '.zip';
self::$storage .= $storage_name . 'rosa-' . Carbon::now()->format('Y-m-d');
self::$storage = $sofascore_data . $storage_name . '/rosa-' . Carbon::now()->format('Y-m-d');
self::$zipfile = $sofascore_data . $storage_name . '/rosa-' . Carbon::now()->format('Y-m-d') . '.zip';
break;
default:
self::$archive_name = 'archive.zip';
self::$storage = $sofascore_data . $storage_name;
self::$zipfile = $sofascore_data . $storage_name . '/archive.zip';
break;
}
if ($debug)
Notice::note("\nStore:\t" . Sofascore::$storage . "\nZip:\t" . Sofascore::$zipfile, 'c');
}
}
@@ -12,11 +12,9 @@ class ZipFolder
public static function create()
{
$zipFilePath = Sofascore::$storage . Sofascore::$archive_name;
$zip = new ZipArchive();
if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {
if ($zip->open(Sofascore::$zipfile, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {
if (is_dir(Sofascore::$storage)) {
@@ -3,37 +3,78 @@
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grapper\Sofascore\Helper\Strings;
use App\Console\Commands\Grapper\Sofascore\Helper\ZipFolder;
use App\Console\Commands\Nuh;
use Spatie\SimpleExcel\SimpleExcelWriter;
use App\Utilities\Notice;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class MakeExcel
{
public static $FOLDER = 'Season-25-26-Major-Leagues';
public static $MAXCOLUMNS = 1000;
public static function create()
{
$files = ZipFolder::get_tree(Sofascore::$storage);
ini_set("memory_limit", -1);
$writer = SimpleExcelWriter::create(Sofascore::$storage . '.xlsx');
$debug = Nuh::$options['d'] ?? 0;
foreach ($files as $file) {
if ($debug) {
Notice::note("Make Excel", 'bb');
}
$name = str_replace('.json', '', basename($file));
$writer->addHeader(['#TEAM# ' . $name]);
if ($debug) {
Notice::note("Folder to Import: " . self::$FOLDER . "\nMaximum in Excel: " . self::$MAXCOLUMNS, 'b');
}
$data = file_get_contents($file);
$files = self::load_files();
$arr = json_decode($data, true);
foreach ($files as $key => $value) {
if (isset($arr['players']) && is_array($arr['players'])) {
foreach ($arr['players'] as $value) {
if ($value) {
$writer->addRow([$name => json_encode($value)]);
}
$from = $key * self::$MAXCOLUMNS + 1;
$key++;
$to = $key * self::$MAXCOLUMNS;
$filename = self::$FOLDER . '-' . $from . '-' . $to . '.xlsx';
$spreadsheet = new Spreadsheet;
$spreadsheet->getProperties()->setTitle($filename);
$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 $val) {
$row++;
$activeWorksheet->setCellValue([$column, $row], trim($val));
}
$column++;
}
$spreadsheet->setActiveSheetIndex(0);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save(Sofascore::$storage . '/' . $filename);
}
}
public static function load_files()
{
$files = ZipFolder::get_tree(Sofascore::$storage . '/' . self::$FOLDER);
$filtered = [];
foreach ($files as $file) {
$path_parts = pathinfo($file);
if (isset($path_parts['extension']) && $path_parts['extension'] == 'json') {
$filtered[] = $file;
}
}
$writer->close();
return array_chunk($filtered, self::$MAXCOLUMNS);
}
}