Adding tasks to Evolution from Python

It occurred to me that it’d be useful to have some of my scripts throw tasks into my task list in Evolution. Now, this is entirely possible: there’s an API to interact with Evolution from Python code (in Ubuntu as python-evolution. And it works.

>>> import evolution.ecal
>>> print evolution.ecal.list_task_sources()
[('Personal', 'local:system'), ('Shopping', 'local:[email protected]')]
>>> personal_list_uri = evolution.ecal.list_task_sources()[0][1]
>>> personal_list_source = evolution.ecal.open_calendar_source(personal_list_uri, 
    evolution.ecal.CAL_SOURCE_TYPE_TODO)
** (process:14939): DEBUG: Opening calendar source uri: local:system
>>> print [obj.get_summary() for obj in personal_list_source.get_all_objects()]
['My first task', 'My second task']

And we can also add new tasks to an existing list:

>>> new_task = evolution.ecal.ECalComponent(evolution.ecal.CAL_COMPONENT_TODO)
>>> new_task.set_summary('Write task scripts')
>>> personal_list_source.add_object(new_task)

What I can’t seem to do, though, is create a new task list. I ought to be able to. Lists created in Evolution itself seem to have a list uri that looks like local:(time).(number)@(machinename). So I think this should work:

>>> new_list_source = evolution.ecal.open_calendar_source_new_with_absolute_uri('Created from Python', 
  'local:%s00.2.giles' % time.time(),
  evolution.ecal.CAL_SOURCE_TYPE_TODO)
>>> new_task_2 = evolution.ecal.ECalComponent(evolution.ecal.CAL_COMPONENT_TODO)
>>> new_task_2.set_summary('New task in a new list')
>>> new_list_source.add_object(new_task_2)

…but it does not. No errors are thrown, and the newly created source doesn’t seem to be invalid (that is: I can add a newly created task to it, and that doesn’t throw an error either), but… the newly created list (or task) doesn’t show up in Evolution. No idea what I’m doing wrong here; I would guess that I need to somehow “save” the new task list, but I can’t see how? Any suggestions?

I'm currently available for hire, to help you plan, architect, and build new systems, and for technical writing and articles. You can take a look at some projects I've worked on and some of my writing. If you'd like to talk about your upcoming project, do get in touch.

More in the discussion (powered by webmentions)

  • (no mentions, yet.)