Example #1
0
 def __init__(self, email, password):
     CalendarEventEntry.__init__(self)
     self.calendar_service = CalendarService()
     self.calendar_service.email = email
     self.calendar_service.password = password
     self.calendar_service.source = 'Google-Calendar_Python_Sample-1.0'
     try:
         self.calendar_service.ProgrammaticLogin()
     except:
         self.calendar_service = None
Example #2
0
 def __init__(self, email, password): 
     CalendarEventEntry.__init__(self)                                   
     self.calendar_service = CalendarService()
     self.calendar_service.email = email
     self.calendar_service.password = password
     self.calendar_service.source = 'Google-Calendar_Python_Sample-1.0'
     try:
         self.calendar_service.ProgrammaticLogin()
     except:
         self.calendar_service=None
Example #3
0
    def post(self, dt, title, place, type, url):
        """ """
        if url == '':
            url = '/calendar/feeds/default/private/full'

        dt_start = dt + timedelta(hours=-9)
        dt_end   = dt_start + timedelta(hours=1)

        event = CalendarEventEntry()
        event.title = atom.Title(text=self.prefix + title)
        event.where.append(Where(value_string=place))
        event.content = atom.Content(text=type)
        event.when.append(When(
            start_time=dt_start.isoformat() + '.000Z',
            end_time=dt_end.isoformat() + '.000Z'))
        self.client.InsertEvent(event, url)
Example #4
0
    def update(self, sender, instance, retry=False):
        """
        Update or create an entry in Google Calendar for the given instance
        of the sender model type.
        """
        adapter = self.adapters[sender]
        email, password = adapter.get_username_password(instance)

        if adapter.can_save(instance):
            service = self.get_service(email, password)
            event = self.get_event(service, instance) or CalendarEventEntry()
            adapter.get_event_data(instance).populate_event(event)
            if adapter.can_notify(instance):
                event.send_event_notifications = SendEventNotifications(
                    value='true')
            if event.GetEditLink():
                try:
                    service.UpdateEvent(event.GetEditLink().href, event)
                except RequestError:
                    if not retry:
                        self.service = None
                        self.update(sender, instance, retry=True)
                    else:
                        raise

            else:
                new_event = service.InsertEvent(event, self.feed)
                CalendarEvent.objects.set_event_id(instance, self.feed,
                                                   new_event.id.text)
Example #5
0
 def update(self, sender, instance):
     """
     Update or create an entry in Google Calendar for the given instance
     of the sender model type.
     """
     adapter = self.adapters[sender]
     if adapter.can_save(instance):
         service = self.get_service()
         event = self.get_event(service, instance) or CalendarEventEntry()
         adapter.get_event_data(instance).populate_event(event)
         if adapter.can_notify(instance):
             event.send_event_notifications = SendEventNotifications(
                 value='true')
         if event.GetEditLink():
             service.UpdateEvent(event.GetEditLink().href, event)
         else:
             new_event = service.InsertEvent(event, self.feed)
             CalendarEvent.objects.set_event_id(instance, self.feed,
                                                new_event.id.text)
Example #6
0
def uploadToGoogle(ics, email, password, calendar="default", reminder=30, \
                    forceReminder=False):
    """ Upload to your Google Calendar.

	Arguments:
		ics - vobject vevent object.
		email - string, your gcal account name
		password - string, your gcal password
		calendar - string, which calendar to upload to.
		reminder - integer, number of minutes to set
			   reminder for.  Default 30
		forceReminder - boolean, If true, always set a
			        reminder.

	Returns:
		True on success, None on failure

	"""
    # sucks that gdata won't take a timetuple or a isoformat :(
    # it seems that sometimes vobject doesn't give me a
    # datetime object and instead gives me a unicode string.
    # it'd be nice to handle that.
    if type(u' ') == type(ics.vevent.dtstart.value):
        start = time.strptime(ics.vevent.dtstart.value, "%Y%m%dT%H%M%S")
        start = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", start)
    else:
        start = time.strftime("%Y-%m-%dT%H:%M:%S.000Z",
                              ics.vevent.dtstart.value.utctimetuple())

    if type(u' ') == type(ics.vevent.dtend.value):
        end = time.strptime(ics.vevent.dtend.value, "%Y%m%dT%H%M%S")
        end = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", end)
    else:
        end = time.strftime("%Y-%m-%dT%H:%M:%S.000Z",
                            ics.vevent.dtend.value.utctimetuple())

    event = CalendarEventEntry()
    event.title = atom.Title(text=ics.vevent.summary.value)
    if getattr(ics.vevent, "description", None):
        event.content = atom.Content(text=ics.vevent.description.value)
    else:
        event.content = atom.Content(text="")

    if getattr(ics.vevent, "location", None):
        event.where.append(Where(value_string=ics.vevent.location.value))
    else:
        event.where.append(Where(value_string=""))

    # an alarm is set, so go ahead and set a reminder
    if 'valarm' in ics.vevent.contents:
        for when in event.when:
            if len(when.reminder) > 0:
                when.reminder[0].minutes = reminder
            else:
                when.reminder.append(Reminder(minutes=reminder))
    elif forceReminder:
        for when in event.when:
            when.reminder.append(Reminder(minutes=reminder))

    if getattr(ics.vevent, "rrule", None):
        try:
            event.recurrence = Recurrence(
                text=("%s\r\n%s\r\n%s\r\n") %
                ("DTSTART:%s" % (time.strftime(
                    "%Y%m%dT%H%M%S", ics.vevent.dtstart.value.utctimetuple())),
                 "DTEND:%s" % (time.strftime(
                     "%Y%m%dT%H%M%S", ics.vevent.dtend.value.utctimetuple())),
                 "RRULE:%s" % (ics.vevent.rrule.value)))
        except Exception, e:
            print "could not add Recurrence to event, %s" % (str(e))
            return None
Example #7
0
def uploadToGoogle(ics, email, password, calendar="default", reminder=30, \
                   forceReminder=False):
        """ Upload to your Google Calendar.

        Arguments:
        ics - vobject vevent object.
        email - string, your gcal account name
        password - string, your gcal password
        calendar - string, which calendar to upload to.
        reminder - integer, number of minutes to set
                   reminder for.  Default 30
        forceReminder - boolean, If true, always set a
                        reminder.

        Returns:
                 True on success, None on failure

        """
        # sucks that gdata won't take a timetuple or a isoformat :(
        # it seems that sometimes vobject doesn't give me a
        # datetime object and instead gives me a unicode string.
        # it'd be nice to handle that.
        if type(u' ') == type(ics.vevent.dtstart.value):
                start = time.strptime(ics.vevent.dtstart.value, 
                                      "%Y%m%dT%H%M%S")
                start = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", 
                                      start)
        else:
                start = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", 
                                      ics.vevent.dtstart.value.utctimetuple())
                
        if type(u' ') == type(ics.vevent.dtend.value):
                end = time.strptime(ics.vevent.dtend.value, 
                                    "%Y%m%dT%H%M%S")
                end = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", 
                                    end)
        else:
                end = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", 
                                    ics.vevent.dtend.value.utctimetuple())

        event = CalendarEventEntry()
        event.title = atom.Title(text=ics.vevent.summary.value)
        if getattr(ics.vevent, "description", None):
                event.content = atom.Content(text=ics.vevent.description.value)
        else:
                event.content = atom.Content(text="")

        if getattr(ics.vevent, "location", None):
                event.where.append(
                        Where(value_string=ics.vevent.location.value)
                )
        else:
                event.where.append(Where(value_string=""))

        event.when.append(When(start_time=start, end_time=end))

        # an alarm is set, so go ahead and set a reminder
        if 'valarm' in ics.vevent.contents:
                for when in event.when:
                        if len(when.reminder) > 0:
                                when.reminder[0].minutes = reminder
                        else:
                                when.reminder.append(Reminder(minutes=reminder))
        elif forceReminder:
                for when in event.when:
                        when.reminder.append(Reminder(minutes=reminder))

        if getattr(ics.vevent, "rrule", None):
                try:
                        event.recurrence = Recurrence(text=("%s\r\n%s\r\n%s\r\n") % (
                                "DTSTART;VALUE=DATE:%s" % (
                                        time.strftime("%Y%m%d",ics.vevent.dtstart.value.utctimetuple())
                                        ),
                                "DTEND;VALUE=DATE:%s" % (
                                        time.strftime("%Y%m%d",ics.vevent.dtend.value.utctimetuple())
                                        ),
                                "RRULE:%s" % (
                                        ics.vevent.rrule.value
                                        )
                                )
                        )
                except Exception, e:
                        print "could not add Recurrence to event, %s" % (str(e))
                        return None