<?php

mkdir("_stories");

$stories = json_decode(file_get_contents("stories.json"), true);

foreach ($stories as $year => $yearlyStories) {
	foreach ($yearlyStories as $story) {

		$id = $story['objectID'];

		$url = urlencode($story['url']);

		$file = "_stories/$year/$id.md";

		if (!file_exists($file))
		{
			mkdir("_stories/$year");

			echo "[DL-$year] $url" . PHP_EOL;

			$markdown = file_get_contents("http://heckyesmarkdown.com/go/?u=$url");

			file_put_contents($file, $markdown);	
		}
	}
}
