pythonpython-2.7google-calendar-apiicalendarrrule

How to find frequency from a RRULE in Python?


I am trying to find the frequency of a calendar event from a Google Calendar event.

I know that dateutil.rrule.rrulestr has a few methods to parse RRULE. But I have am not aware of a method that can return the frequency of the event.

Any help or pointer would be greatly appreciated.


Solution

  • You may check this documentation. Creating recurring events is similar to creating a regular event with the event resource's recurrence field set.

    Here's a sample Python code using RRULE:

    event = {
      'summary': 'Appointment',
      'location': 'Somewhere',
      'start': {
        'dateTime': '2011-06-03T10:00:00.000-07:00',
        'timeZone': 'America/Los_Angeles'
      },
      'end': {
        'dateTime': '2011-06-03T10:25:00.000-07:00',
        'timeZone': 'America/Los_Angeles'
      },
      'recurrence': [
        'RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z',
      ],
      'attendees': [
        {
          'email': 'attendeeEmail',
          # Other attendee's data...
        },
        # ...
      ],
    }
    
    recurring_event = service.events().insert(calendarId='primary', body=event).execute()
    
    print recurring_event['id']
    

    For more information, you may check this article.