move all to ss IDs
This commit is contained in:
1 parent
09bf62c525
commit
df0a2a9de0
24 files changed
+527
-101
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user