[jp] jppy example requested

Nicholas Piper nick-moongroup at nickpiper.co.uk
Tue Sep 22 19:01:27 EDT 2009


On Tue, 22 Sep 2009, Tom wrote:

> I'm looking at using jppy in a couple of scripts I need to query my task 
> list. I want to query the JPilot database for all tasks that
> * Were completed on a particular date, or
> * Contain that particular date in the Note field
> For each matching task, I want to output either the Task and the first 
> few lines of the Note or, in the case of the Note field matching, just 
> the few lines down from the matching date.
> An example of a matching Note field would be:
> ...
> 21/7/09
> Performed system update
> ...


Try this:


import jppy
import datetime
import re


def summary_for_date(env, date):
    date_string_wanted = date.strftime("%d/%m/%y")
    date_format_re     = re.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}")
    for task in env.taskList.records():
        if task['complete'] and task['due'] == date:
            summary = "%s\n%s" % (task['description'],
            yield summary.strip()
        if date_string_wanted in task['note']:
            collecting = False
            buffer = []
            for line in task['note'].split("\n"):
                if line == date_string_wanted:
                    # the next text must be regarding our wanted date
                    collecting = True
                elif date_format_re.match(line):
                    # we must have hit another date marker, so stop collecting
                    collecting = False
                    # only do this if we're NOT on a date marker line
                    if collecting:
            # it might be that we never found our date marker after all
            if buffer:
                summary = "\n".join(buffer)
                yield summary.strip()

print "Summary for %s" % DATE.date()
env = jppy.environment.Environment()
for summary in summary_for_date(env, DATE):
    print "-" * 80
    print summary

If you're using jppy <= 0.0.48, you'd use "for task in jppy.taskList():".

Note there is a jppy-specific mailing list at



More information about the Jpilot mailing list