Schedule Importer for TaskWarrior

I just wrote another useful little script. This one takes a CSV representation of any schedule in this form and imports it into TaskWarrior for easy time management

Week 1 Read pages 1-25
Week 2 Read pages 26-50
Do Exercise 1
Week 3 Read pages 51-75

The week column can contain anything. The script will warn you if it doesn’t recognize it but it’s really just using the presence of text in column 1 to mark the changeover to a new time period.

Using it is also quick and easy:

  1. Copy-paste the table from whatever format you got it in (HTML and MS Word tables work for me) into a spreadsheet tool like Excel or OpenOffice/LibreOffice Calc.
  2. If necessary, delete columns so column 2 holds task names.
  3. If necessary, alternate between Delete and the down arrow, rapid-fire, so only rows which mark a new time period have content in column 1.
  4. Save the file as CSV.
  5. Run the script like this:
    python ~/schedule.csv \
        --start=2013-02-01 --deadline=2013-06-30           \
        --project=EXMPL101 > ~/schedule.json
    task import ~/schedule.json

All arguments are optional. By providing a deadline, you let script automatically adjust the definition of a week if there aren’t enough weeks before the given date.

If you want to use it for periods other than weeks, specify --increment=DAYS to override the default of 7.  The script will use the smaller of --increment and the value calculated from --deadline if both are provided. See --help for more details.

As usual, here’s the download link for if you don’t want to scroll past the embed. I’ve only tested it on Lubuntu Linux 12.04 LTS under CPython 2.7.3, CPython 3.2.3, and PyPy 1.9.0, but it should run anywhere.

(It was surprisingly complicated since TaskWarrior currently has a very primitive line-by-line JSON parser that reminds me of the parsers I wrote using things like sed and regexes when I was young and ignorant. Take a look at the last few lines if you want to see how I mixed json.dumps(indent=0) and string-formatting operators to securely and robustly get the newline use task import demands.)

CC BY-SA 4.0 Schedule Importer for TaskWarrior by Stephan Sokolow is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

This entry was posted in Geek Stuff. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution under the same terms as the associated post.

All comments are moderated. If your comment is generic enough to apply to any post, it will be assumed to be spam. Borderline comments will have their URL field erased before being approved.