Thanks Will give it a try over the weekend cheers On Wednesday, May 23, 2012 9:56:46 AM UTC+2, cjparsons74 wrote:
> Here is a script I hacked together for my own use. If it gets messed > up by being e-mailed them send me a message and I'll send it as an > attachment. > > # Script to import tasks from one folder within the Inbox tree in > Outlook > # (outlookExportFolder) and put them into mGSD. It is very crude and > only uses search > # and replace to modify the mGSD file. It makes a backup in a > directory > # (backupLocation), which must exist. After the import it puts the > message in the > # folder named as outlookArchiveFolder > # > # The imported message is put into the "Import" context. > # > # Because it modifies the mGSD file directly you must Save (or close) > the mGSD page > # in your browser before running the script. > # > # You need to install Python 2.6 or 2.7 > # http://www.activestate.com/activepython > # > # and the win32 extensions e.g. > # http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/ > # > # No warranty is supplied with this script. There is very little error > checking. It > # is probable that attempting to import some messages will corrupt > your mgsd file. > # (hence the backup). When trying it out you should work on a copy of > your "real" > # mGSD file. > # > # Works for me with Outlook 2003 and python 2.6.6 and e-mail message > items. > > # Configuration parameters each user should change > # > # (C) Chris Parsons 2012. cjparsons1 at yahoo dot co dot uk This > script may be used in the course of commercial > # business, adapted and distributed providing licence remains intact. > > backupLocation = r"H:\twbackup" > mgsdFile = r"H:\mgsd.html" > outlookExportFolder = r"Export" > outlookArchiveFolder = r"KF2M" > > import os > import ctypes > import shutil > import codecs > import os.path > import win32com.client > import win32gui > from win32com.shell import shell, shellcon > from datetime import timedelta,datetime,date > import re > import string > import pywintypes > > # Open outlook > oOutlook = > win32com.client.gencache.EnsureDispatch("Outlook.Application") > mapi = oOutlook.GetNamespace("MAPI") > inbox = mapi.GetDefaultFolder(6) #inbox > exportFolder = inbox.Folders.Item(outlookExportFolder) > kf2mFolder = inbox.Folders.Item(outlookArchiveFolder) > > def ExportToMGSD(title="Unnamed Task",body=""): > # make bakcup > dateString = datetime.now().strftime("%Y-%m-%d.%H.%M.%S.%f") > backupFile = os.path.join(backupLocation, "exportbackup.html" + > "."+dateString) > > shutil.copyfile(mgsdFile, backupFile) > > # place to insert new items > patt = re.compile('(<div title="InstantTimestampPlugin)') > > content = "" > try: > with codecs.open(mgsdFile, 'r', 'utf-8') as f: > content = f.read() > except IOError: > pass > > if len(content): > dateString = datetime.now().strftime("%Y%m%d%H%M") > content = patt.sub(r'<div title="%s" modifier="Import" > created="%s" modified="%s" tags="Work Next Action Import" > changecount="1"><pre>%s</pre></div>\n\1' % (title, dateString, > dateString, body), content, count=1) > with codecs.open(mgsdFile, 'w', 'utf-8') as f: > f.write(content) > else: > ctypes.windll.user32.MessageBoxA(None, 'Could not open mgsd > file', 'Error', 0) > > def ExportMsgToMGSD(msg): > print msg.Subject > ExportToMGSD(msg.Subject.strip(), msg.Body.strip()) > > # For each message in the Export folder > lastSubject = "" > for i in range(len(exportFolder.Items)): > # The message we want is always Item #1 because messages are bein > gmoved out of > # the folder when we've dealt with them > m = exportFolder.Items.Item(1) > # Safety check that we're not in a cycle with the same message > if m.Subject == lastSubject: > ctypes.windll.user32.MessageBoxA(None, 'Seem to be stuck on same > message', 'Error', 0) > break > lastSubject = m.Subject > ExportMsgToMGSD(m) > m.Move(kf2mFolder) > > -- You received this message because you are subscribed to the Google Groups "GTD TiddlyWiki" group. To view this discussion on the web visit https://groups.google.com/d/msg/gtd-tiddlywiki/-/Q1pd3S39EYQJ. To post to this group, send email to gtd-tiddlywiki@googlegroups.com. To unsubscribe from this group, send email to gtd-tiddlywiki+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/gtd-tiddlywiki?hl=en.