"""Script to take scheduled items in an org-mode file and export to CSV. Once you have the CSV file you can import it into Microsoft Outlook or Google's Calendar. """ import glob, csv, datetime, sys import Orgnode def MakeCSV(globPattern, output, onlyToday=True, defaultReminder=datetime.timedelta(minutes=5)): """Make a CSV file representing all scheduled items. INPUTS: -- globPattern: File name or pattern (e.g., ~/org/*.org) representing files to process. -- output: Name of output csv file to write to. -- onlyToday=True: Whether to only output today's items (if True) or output all items (if False). -- defaultReminder=datetime.timedelta(minutes=5): Offset for reminders. A reminder will be generated this amount prior to each scheduled item with a start time. ------------------------------------------------------- PURPOSE: Create a CSV file from org-mode files so that the schedule can be imported into Microsoft Outlook or Google calendar. """ today = datetime.date.today().timetuple()[0:3] out = open(output, 'wb') writer = csv.writer(out) writer.writerow(["Subject", "Start Date", "Start Time", "End Date", "End Time", "All day event", "Description", "Show time as", "Location", "Reminder Date", "Reminder Time", "Reminder on/off"]) for fileName in glob.glob(globPattern): for n in Orgnode.makelist(fileName): if (n.scheduled and ( not onlyToday or n.scheduled.timetuple()[0:3] == today)): row = [n.headline, n.scheduled, n.starttime, n.scheduled, n.endtime, 'FALSE', n.body, 3, '', '', '', ''] if (row[2]): row[2] = row[2].strftime('%H:%M:00') if (row[4]): row[4] = row[4].strftime('%H:%M:00') if (row[2] and defaultReminder is not None): row[-3] = row[1] row[-2] = (n.starttime-defaultReminder).strftime('%H:%M:00') row[-1] = "TRUE" writer.writerow(row) def MakeUsage(): 'Return string representing usage information.' return ''' Org2CSV.py --globPatttern= --output= [--onlyToday=] where is a wild card pattern for all org-mode files to process, is the name of an output csv file, and is either "True" or "False". ''' if __name__ == '__main__': argvDict = dict([item.split('=') for item in sys.argv[1:] if item]) argvDict = dict([(k.lstrip('-'), v) for (k,v) in argvDict.items()]) onlyTodayArg = argvDict.get('onlyToday', True) argvDict['onlyToday'] = False if ( onlyTodayArg is False or onlyTodayArg == 'False') else onlyTodayArg try: MakeCSV(**argvDict) except Exception, e: print 'Unable to make csv file due to exception:\n%s\nUsage:\n%s' % ( str(e), MakeUsage())