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()
thanks for sharing Mustafa.
do you know how to create an hyperlink into the a task?
I have tried adding something like
Click Here
but it did not work