Skip to content

Instantly share code, notes, and snippets.

@m4tthumphrey
Created April 10, 2025 10:16
Show Gist options
  • Save m4tthumphrey/a9bd046446bcaecdf9f21932976e1194 to your computer and use it in GitHub Desktop.
Save m4tthumphrey/a9bd046446bcaecdf9f21932976e1194 to your computer and use it in GitHub Desktop.
Generate JSON and CSV formatting list of World Cup 2026 Fixtures
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
class GenerateWorldCupFixturesCommand extends Command
{
protected $name = 'app:world-cup:fixtures';
public function handle()
{
$input = file(storage_path('fixtures.txt'));
$csv = fopen(storage_path('fixtures.csv'), 'w');
$fixtures = [];
$date = null;
$stage = null;
$separator = ' - ';
fputcsv($csv, [
'Number',
'Date',
'Description',
'State',
'Group 1',
'Group 2',
'Venue'
]);
foreach ($input as $line) {
$line = trim($line);
if (!$line || str_starts_with($line, 'FIFA World Cup 26')) {
continue;
}
$line = str_replace(' – ', $separator, $line);
if (preg_match('/^Match ([0-9]+) - (.*)$/', $line, $matches)) {
$venue = substr($matches[2], strrpos($matches[2], $separator) + strlen($separator));
$number = $matches[1];
$groups = [null, null];
if (preg_match_all('/Group ([A-Z\/]+)/', $line, $matches)) {
foreach ($matches[1] as $index => $group) {
$groups[$index] = $group;
}
}
$fixture = [
'number' => (int) $number,
'date' => $date->format('Y-m-d'),
'match' => $line,
'stage' => $stage,
'group_1' => $groups[0],
'group_2' => $groups[1],
'venue' => $venue
];
$fixtures[] = $fixture;
fputcsv($csv, $fixture);
} else {
$date = new Carbon($line);
if ($date >= '2026-07-19') {
$stage = 'Final';
} elseif ($date >= '2026-07-18') {
$stage = '3rd Place Play-Off';
} elseif ($date >= '2026-07-18') {
$stage = '3rd Place Play-Off';
} elseif ($date >= '2026-07-14') {
$stage = 'Semi Finals';
} elseif ($date >= '2026-07-09') {
$stage = 'Quarter Finals';
} elseif ($date >= '2026-07-04') {
$stage = 'Last 16';
} elseif ($date >= '2026-07-18') {
$stage = '3rd Place Play-Off';
} elseif ($date >= '2026-06-28') {
$stage = 'Last 32';
} else {
$stage = 'Group Stage';
}
}
}
file_put_contents(storage_path('fixtures.json'), json_encode($fixtures, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}
}
@m4tthumphrey
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment