Last active
February 20, 2016 01:01
-
-
Save ryo-utsunomiya/8002f3adb1a448172339 to your computer and use it in GitHub Desktop.
Revisions
-
ryo-utsunomiya revised this gist
Feb 20, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -86,7 +86,7 @@ public function addSeries($taskName, $times = 1) throw new \InvalidArgumentException(); } for ($i = 1; $i <= $times; $i++) { $this->addTask(sprintf('%s %d/%d', $taskName, $i, $times)); } } -
ryo-utsunomiya revised this gist
Jan 30, 2016 . 1 changed file with 9 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,12 +4,16 @@ // // todoist_template_editor.php // // Usage: $ php todoist_template_editor.php 'do something' 10 // => output todoist template 'do something.csv'. if (!isset($argv[1])) { echo 'Usage: $ php todoist_template_editor.php \'do something\' 10' . PHP_EOL; exit(1); } $taskName = (string)$argv[1]; $times = isset($argv[2]) ? (int)$argv[2] : 1; $editor = new TodoistTemplateEditor('Utsunomiya (4971726)'); $editor->addSeries($taskName, $times); @@ -76,9 +80,9 @@ public function addTask($content, $priority = 4) * @param string $taskName * @param int $times */ public function addSeries($taskName, $times = 1) { if ($times < 1) { throw new \InvalidArgumentException(); } -
ryo-utsunomiya created this gist
Jan 30, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,117 @@ #!/usr/bin/env php <?php // // todoist_template_editor.php // // Usage: // $ php todoist_template_editor.php 'do something' 10 // => output todoist template 'do something.csv'. $taskName = (string)$argv[1]; $times = (int)$argv[2]; $editor = new TodoistTemplateEditor('Utsunomiya (4971726)'); $editor->addSeries($taskName, $times); $editor->write($taskName . '.csv'); class TodoistTemplateEditor { /** * @var string */ private $author; /** * @var array */ private $table; /** * Constructor. * * @param string $author Author of task. */ public function __construct($author) { $this->author = $author; $this->table = [ [ 'TYPE', 'CONTENT', 'PRIORITY', 'INDENT', 'AUTHOR', 'RESPONSIBLE', 'DATE', 'DATE_LANG' ], ]; } /** * Add a task. * * @param string $content * @param int $priority */ public function addTask($content, $priority = 4) { $line = [ 'task', (string)$content, $priority, 1, // indent $this->author, // author '', // responsible '', // date 'en', // date_lang ]; $this->table[] = $line; } /** * Add series of task. * * @param string $taskName * @param int $times */ public function addSeries($taskName, $times) { if ($times <= 0) { throw new \InvalidArgumentException(); } for ($i = 0; $i < $times; $i++) { $this->addTask(sprintf('%s %d/%d', $taskName, $i, $times)); } } /** * Write table content to CSV file. * * @param string $filePath Output csv file path. */ public function write($filePath) { $fp = fopen($filePath, 'w'); if (!$fp) { throw new \RuntimeException(); } foreach ($this->table as $line) { fputcsv($fp, $line); } fclose($fp); } /** * Show all table data. */ public function dump() { var_dump($this->table); } }