Skip to content

Instantly share code, notes, and snippets.

@kostajh
Created February 24, 2014 20:59
Show Gist options
  • Save kostajh/9196942 to your computer and use it in GitHub Desktop.
Save kostajh/9196942 to your computer and use it in GitHub Desktop.
Ugly script to find malformed entries in taskwarrior data.
<?php
$dir = '/home/kosta/.task';
$files = array('pending.data', 'completed.data', 'undo.data', 'undo_remote.data');
foreach ($files as $file) {
$handle = fopen("/home/kosta/.task/" . $file, "r");
print 'Looking at file ' . $file . "\n";
$line_number = 0;
if ($handle) {
while (($line = fgets($handle)) !== false) {
$line_number++;
if (trim($line) == '---') {
continue;
}
if (strpos($line, 'time') === 0) {
continue;
}
if (strpos($line, 'old') === 0 || strpos($line, 'new') === 0) {
$line = substr($line, 4);
}
if (strpos($line, '[') !== 0) {
print 'Missing opening bracket on line ' . $line_number;
}
if (substr(trim($line), -1) !== ']') {
print 'Missing closing bracket on line ' . $line_number . "\n";
}
if (substr_count($line, '[') > 1) {
print 'Opening bracket occurs twice on line ' . $line_number . "\n";
}
if (substr_count($line, ']') > 1) {
print 'Closing bracket occurs twice on line ' . $line_number . "\n";
}
if (!strpos($line, 'status')) {
print 'Could not find status on line ' . $line_number . "\n";
}
if (!(strpos($line, 'pending') || strpos($line, 'completed') || strpos($line, 'deleted') || strpos($line, 'waiting') || strpos($line, 'recurring'))) {
print 'Suspect line ' . $line_number . "\n";
print $line . "\n";
}
}
} else {
print 'err';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment