Create Outlook tasks from Taskcoach task file

This is a script which creates Outlook tasks from each task out of a Taskcoach XML-file. I saved my task to file named “My_Tasks.tsk”. Please modify it for your needs.

from xml.dom import minidom
import win32com.client
from datetime import datetime
try:
   oOutlookApp = win32com.client.gencache.EnsureDispatch("Outlook.Application")
except:
   print "MSOutlook: unable to load Outlook"

# this should use more try/except blocks or nested blocks
#onMAPI = oOutlookApp.GetNamespace("MAPI")
#ofTasks = onMAPI.GetDefaultFolder(win32com.client.constants.olFolderTasks)


xml = r'My_Tasks.tsk'

xmldoc = minidom.parse(xml)
tcTasks = xmldoc.getElementsByTagName('task')
print 'Creating %s tasks'%len(tcTasks)

for tcTask in tcTasks:
    print 'Saving %s [%s]' % (tcTask.getAttribute('subject'), tcTask.getAttribute('status'))
    newtask = oOutlookApp.CreateItem(win32com.client.constants.olTaskItem)
    if tcTask.getAttribute('expandedContexts') != 'Dummy': #Todo: Unsichere Ecke
        newtask.Subject = tcTask.getAttribute('subject')
        for note in tcTask.getElementsByTagName('note'):
            newnote = oOutlookApp.CreateItem(win32com.client.constants.olNoteItem)
            newnote.Body += note.getAttribute('subject') + ':\n'
            for nodetext in note.getElementsByTagName('description'):
                newnote.Body += nodetext.firstChild.data
            newnote.Save()
            #newtask.Links.Add(newnote)

        for tasktext in tcTask.getElementsByTagName('description'):
                newtask.Body += tasktext.firstChild.data
        for attachment in tcTask.getElementsByTagName('attachment'):
            newtask.Body += 'File attachment %s:\n%s\n' % (attachment.getAttribute('subject'), attachment.getAttribute('location'))

        if tcTask.getAttribute('duedate') not in ['', None]:
            newtask.DueDate = tcTask.getAttribute('duedate')
        if tcTask.getAttribute('startdate') not in ['', None]:
            newtask.StartDate = tcTask.getAttribute('startdate')
        #elif tcTask.getAttribute('percentageComplete') in ['0', 0]:
            #newtask.Status = 0
            #newtask.PercentComplete = 0
        if tcTask.getAttribute('percentageComplete') in ['100', 100]:
            newtask.Status = 2
            newtask.PercentComplete = 100
        if tcTask.getAttribute('percentageComplete') not in ['', None, '100', 100]:
            newtask.PercentComplete = int(tcTask.getAttribute('percentageComplete'))
            newtask.Status = 5
        newtask.Save()

One Reply to “Create Outlook tasks from Taskcoach task file”

Leave a Reply to Anonymous Cancel reply

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