Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion scraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
// 日付付きの JSON ファイルとして保存(例: docs/v2/20250826.json)
// 最新データとして today.json にも保存
$storage = new ProgramStorage();
$storage->save($programs, "docs/{$version}/" . $date->format('Ymd') . '.json');
$storage->save($programs, "docs/{$version}/" . $date->format('Y') . '/' . $date->format('Ymd') . '.json');
$storage->save($programs, "docs/{$version}/today.json");
11 changes: 10 additions & 1 deletion src/ProgramStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ final class ProgramStorage
public function save(array $programs, string $path): void
{
$contents = json_encode(['programs' => $programs]);
if ($contents !== false && file_put_contents($path, $contents) === false) {
if ($contents === false) {
throw new \RuntimeException("Failed to encode programs to JSON");
}

$dir = dirname($path);
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
throw new \RuntimeException("Failed to create directory: {$dir}");
}

if (file_put_contents($path, $contents) === false) {
throw new \RuntimeException("Failed to save programs to {$path}");
}
}
Expand Down