I’ve been meaning to throw this out there for a bit. I wrote a little python shim to connect mutt to Google Calendar. My particular use-case is as follows. I use fetchmail to connect to a Microsoft Exchange Server at work which delivers mail into an IMAP account that I check with mutt. Appointments and conference calls show up as .ics files attached to messages. I use Google Calendar connected to my BlackBerry to keep track of all the stuff I do so I need a quick and easy way to get those events out of mutt into my Google Calendar.
Enter ics-gcal.py.
I associate this script to the ics / vcs files and simply exec the attachment from within mutt. This adds it to my Google Calendar.
You can find the script in my CVS web repository.
I’d be super interested if anyone else finds this useful.
Tags: google, mutt, python, technology
Hello,
I have been using your script for a couple days now and have added calendar entries to my Google calendar with no problems. One thing I did change though was the mailcap entry. I removed the ‘copiousoutput’ entry. With the ‘copiousoutput’ entry, I was getting new/duplicate calendar entries added every time I was viewing an email with an event. Without the ‘copiousoutput’ option, I have to go to manually select the ICS attachment, which is what I want.
A couple things I would like to see added:
1. Ability to specify which Google calendar I add the event to.
2. Add a flag to specify the length of the reminder.
I’ll try (with my crippled python skills) to see if I can add this myself, but my feelings wouldn’t be hurt if you made this magic happen. :)
At any rate, thanks for the nice hack. Cheers!
I’m glad you like it.
Strange about the ‘copiousoutput’ thing, I use it and don’t get duplicates, and according to the mailcap(5) manpage copiousoutput is just used to tell the MUA you are going to have a bunch of lines of text and should pipe the command through a pager, strictly speaking we probably don’t NEED it but it shouldn’t be creating duplicates. I will look into that more.
With respect to your feature requests, please give the updated script a shot, version 1.2 should be available in the CVS repo
http://bagend.ub3rgeek.net/cgi-bin/cvsweb.cgi/misc-scripts/ics-gcal.py
Many thanks for the fast turnaround! Version 1.2 does indeed add the event to the calendar I specify. But, it does not add a reminder. Regardless of using the ‘-r’ flag or not, no reminder is set.
Oh, I also had to correct your ‘getopt’ call to include the new flags:
optlist, args = getopt.getopt(argv, “hu:p:f:c:r:”)
Not to be too picky, but you misspell calendar in a couple spots:
print “cannot login to Google Calnedar: %s” % ( str(e) )
print “cannot upload event to Google Calnedar: %s” % ( str(e) )
I will be glad to test another new version (if/when there is one). Cheers!
Yikes, pretty lame of me to forget to update the getopt() call :( I fixed that and my misspellings. With respect to the reminder I’m wondering if your invitation that you are importing perhaps does not have an alarm set? I only set a reminder if the input file has an alarm set. I added the -R flag to force the addition of a reminder even if the event doesn’t have an alarm. Let me know if that fixes it for you.
New version is 1.3 and is in the same spot as 1.2
I’m glad you’re getting some use out of this :)
–Matt
Hi Matt,
I ran into one issue with 1.3:
Traceback (most recent call last):
File “/home/bboles/bin/ics-gcal.py”, line 236, in
sys.exit(Main(sys.argv[1:]))
File “/home/bboles/bin/ics-gcal.py”, line 230, in Main
if not uploadToGoogle(ics, email, password, calendar, reminder, force):
File “/home/bboles/bin/ics-gcal.py”, line 146, in uploadToGoogle
when.reminder.append(Reminder(minutes=reminder))
UnboundLocalError: local variable ‘when’ referenced before assignment
I changed line 146, so that ‘when’ gets assigned appropriately:
elif forceReminder:
for when in event.when:
when.reminder.append(Reminder(minutes=reminder))
After my change, it worked like a champ! Thanks for the explanation on the ‘alarm’ setting of the ICS file. Looking through my events, none seem to automatically set an alarm/reminder so the ‘-R’ flag makes things work like I want them to work. Way cool.
I’ll continue to use and report if anything else comes up. Many thanks!
I just tried out v1.5. It looks like you inadvertently undid the 1.4 changes. After adding back the 1.4 changes, I also made this change in processing the event description:
event.title = atom.Title(text=ics.vevent.summary.value)
if getattr(ics.vevent, “description”, None):
event.content = atom.Content(text=ics.vevent.description.value)
Not all of my events have a description, so the script was barfing when there was none.
I also tried to add a recurring event. Here is the (what I think) is the applicable line from my ics file:
RRULE:COUNT=;FREQ=WEEKLY;INTERVAL=1
So this should mean that this event should occur once weekly, indefinitely. When trying to process, I get this error:
cannot upload event to Google Calendar: {’status’: 400, ‘body’: ‘Failed to process recurrence rule’, ‘reason’: ‘Bad Request’}
I’ll test your update if you have any ideas on how to fix. Thanks! :)
I integrated your fixes for the regression and the Description into 1.6 I think the RRULE is gonna be trickier. The problem I think is the “COUNT=;” parameter. It seems the way Gcal wants this is to omit the COUNT value completely. I’ll see if I can whip something up to re.sub() that out…
Hi,
Thanks for your little program, it fitted just right. I have made some minor tweaks (corrections, fixes, whatever), and I would like to give them back to you. If you are interested, please email me and I’ll show you what I’ve done.