diff --git a/app/Parser.php b/app/Parser.php index b74cf7b9f7..3e317120e8 100644 --- a/app/Parser.php +++ b/app/Parser.php @@ -2,12 +2,26 @@ namespace App; -use Exception; - final class Parser { public function parse(string $inputPath, string $outputPath): void { - throw new Exception('TODO'); + $results = []; + $resource = \fopen($inputPath, 'r'); + + while (($line = \fgets($resource)) !== false) { + $path = \substr($line, 19, -27); + $date = \substr($line, -26, 10); + $results[$path][$date] = ($results[$path][$date] ?? 0) + 1; + } + \fclose($resource); + + foreach ($results as $path => &$path_arr) { + \ksort($path_arr); + } + + $out = \fopen($outputPath, 'w'); + \fwrite($out, \json_encode($results, \JSON_PRETTY_PRINT)); + \fclose($out); } -} \ No newline at end of file +}