def convert_event_into_todo_strings(event): what = imap_utils.safe_get_event_value(event, 'summary.value', 'From IMAP') where = imap_utils.safe_get_event_value(event, 'location.value', 'Unspecified') when = imap_utils.safe_get_event_value(event, 'dtstart.value', datetime.datetime.now()) return "+ %s - [IMAP] %s: %s" % (when.strftime("%Y-%m-%d %H:%M"), where, what)
def add_to_google_calendar(calendar_service, item, calendar_id='default'): title = imap_utils.safe_get_event_value(item, 'summary.value', 'Imported Event') description = imap_utils.safe_get_event_value(item, 'description.value', 'Imported Event') where = imap_utils.safe_get_event_value(item, 'location.value', 'Unspecified') start_time = imap_utils.safe_get_event_value(item, 'dtstart.value', datetime.datetime.now()) end_time = imap_utils.safe_get_event_value( item, 'dtend.value', datetime.datetime.now() + datetime.timedelta(hours=1)) attendees = [ "%s [%s]" % (a.cn_paramlist[0], a.value) for a in imap_utils.safe_get_event_value(item, 'attendee_list', []) ] # tack the attendees list to the bottom of the thing (should really add it to 'event.who') if len(attendees): description = description + "\n-- Attendees:\n" + "\n".join(attendees) event = gdata.calendar.CalendarEventEntry() event.title = atom.Title(text=title) event.content = atom.Content(text=description) event.where.append(gdata.calendar.Where(value_string=where)) if start_time is None: # Use current time for the start_time start_time = datetime.datetime.now() if end_time is None: # have the event last 1 hour end_time = datetime.datetime.now() + datetime.timedelta(hour=1) # http://code.google.com/apis/calendar/data/1.0/developers_guide_python.html#Reminders event.when.append( gdata.calendar.When(start_time=UTC.to_utc_str(start_time), end_time=UTC.to_utc_str(end_time), reminder=gdata.calendar.Reminder(minutes=1, method='alert'))) exception = None for i in range(3): try: new_event = calendar_service.InsertEvent( event, '/calendar/feeds/%s/private/full' % calendar_id) return new_event except gdata.service.RequestError, e: print "Got 302, trying again..." exception = e time.sleep(3)
def add_to_google_calendar(calendar_service, item, calendar_id='default'): title = imap_utils.safe_get_event_value(item, 'summary.value', 'Imported Event') description = imap_utils.safe_get_event_value(item, 'description.value', 'Imported Event') where = imap_utils.safe_get_event_value(item, 'location.value', 'Unspecified') start_time = imap_utils.safe_get_event_value(item, 'dtstart.value', datetime.datetime.now()) end_time = imap_utils.safe_get_event_value(item, 'dtend.value', datetime.datetime.now() + datetime.timedelta(hours=1)) attendees = ["%s [%s]" % (a.cn_paramlist[0], a.value) for a in imap_utils.safe_get_event_value(item, 'attendee_list', [])] # tack the attendees list to the bottom of the thing (should really add it to 'event.who') if len(attendees): description = description + "\n-- Attendees:\n" + "\n".join(attendees) event = gdata.calendar.CalendarEventEntry() event.title = atom.Title(text=title) event.content = atom.Content(text=description) event.where.append(gdata.calendar.Where(value_string=where)) if start_time is None: # Use current time for the start_time start_time = datetime.datetime.now() if end_time is None: # have the event last 1 hour end_time = datetime.datetime.now() + datetime.timedelta(hour=1) # http://code.google.com/apis/calendar/data/1.0/developers_guide_python.html#Reminders event.when.append(gdata.calendar.When(start_time=UTC.to_utc_str(start_time), end_time=UTC.to_utc_str(end_time), reminder=gdata.calendar.Reminder(minutes=1, method='alert') )) exception = None for i in range(3): try: new_event = calendar_service.InsertEvent(event, '/calendar/feeds/%s/private/full' % calendar_id) return new_event except gdata.service.RequestError, e: print "Got 302, trying again..." exception = e time.sleep(3)