page-converter-pro.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. $file = explode(PHP_EOL, file_get_contents("radon-page-4.md"));
  3. // remove EOF_LINE
  4. array_pop($file);
  5. $sqlReadings = array();
  6. $sqlNotes = array();
  7. $yr; $mo; $dy;
  8. foreach($file as $line) {
  9. if("2021" === substr($line, 0, 4)) {
  10. $yr = strtok($line, " ");
  11. $mo = strtok(" ");
  12. $dy = strtok(" ");
  13. //echo "{$yr} {$mo} {$dy}" . PHP_EOL;
  14. continue;
  15. }
  16. //echo "line: {$line}" . PHP_EOL; continue;
  17. $a = 100 * strtok($line, " ");
  18. $b = 100 * strtok(" ");
  19. $c = 100 * strtok(" ");
  20. $hour = strtok(" ");
  21. $notes = strtok("\n");
  22. //echo "{$a},{$b},{$c},{$hour}" . PHP_EOL . " >{$notes}" . PHP_EOL;
  23. $seconds = strtotime("{$dy} {$mo} {$yr} {$hour}");
  24. $sqlReadings[] = "('A', {$seconds}, {$a})";
  25. $sqlReadings[] = "('C', {$seconds}, {$b})";
  26. $sqlReadings[] = "('B', {$seconds}, {$c})";
  27. if(0 == $c) array_pop($sqlReadings);
  28. if(false === $notes) continue;
  29. $sqlNotes[] = "('note', {$seconds}, '{$notes}')";
  30. }
  31. $sqlReadings = "INSERT INTO radonLog (id, time, reading) VALUES " . PHP_EOL . implode("," . PHP_EOL, $sqlReadings) . ";";
  32. $sqlNotes = "INSERT INTO locationLog (id, time, description) VALUES " . PHP_EOL . implode("," . PHP_EOL, $sqlNotes) . ";";
  33. echo $sqlReadings;
  34. //echo $sqlNotes;