• Download Gist
StackOverflow Reputation Audit Parser.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
<?php
$audit = file_get_contents('audit.txt');
$audit = split("\n", $audit);
$data = Array();
for ($i=0; $i!=count($audit); $i++) {
$line = $audit[$i];
$datatype = substr($line, 0, 1);
switch ($datatype) {
case '-':
$day = substr($line, 3, 10);
$repPlus = str_replace(' ', '', substr($line, 19, 3));
if (isset($_GET['debug'])) {
echo 'Found day '.$day.' on line '.$i.' (rep +'.$repPlus.')<br />';
}
$data[] = Array('date' => $day, 'rep' => $repPlus);
break;
case ' ':
if (isset($_GET['debug'])) {
echo 'Skipped day detail on line '.$i.'<br />';
}
break;
case '*':
if (isset($_GET['debug'])) {
echo $i.': '.substr($line, 2).'<br />';
}
break;
default:
if (isset($_GET['debug'])) {
echo 'Skipped unknown on line '.$i.'<br />';
}
break;
}
}
if (isset($_GET['debug'])) {
echo '<hr /><b>JSON code follows</b><br /><code>';
}
echo json_encode($data);
if (isset($_GET['debug'])) {
echo '</code>';
}
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.