如何为谷歌日历API制定自定义重复规则?

2024-05-19 22:10:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个项目,在这个项目中,我必须在谷歌日历中为最终用户安排一些重复的活动。我一直在使用日历的pythonapi,到目前为止,根据rfc5545标准,使用最常见的循环规则没有问题

然而,在没有模式的情况下安排经常性事件会有帮助。我的意思是,我不想告诉谷歌每周安排3次周五的活动,而是想指定这组活动的日期,并让所有活动都在同一个活动ID下注册

有人知道这是否可能吗?任何意见将不胜感激


Tags: 项目idpythonapi标准规则模式事件情况
2条回答

这是可能的,但不是很容易。您提到的标准实际上在这里描述了:Link to standard page 120

  The recurrence dates, if specified, are used in computing the
  recurrence set.  The recurrence set is the complete set of
  recurrence instances for a calendar component.  The recurrence set
  is generated by considering the initial "DTSTART" property along
  with the "RRULE", "RDATE", and "EXDATE" properties contained
  within the recurring component.  The "DTSTART" property defines
  the first instance in the recurrence set.  The "DTSTART" property
  value SHOULD match the pattern of the recurrence rule, if
  specified.  The recurrence set generated with a "DTSTART" property
  value that doesn't match the pattern of the rule is undefined.
  The final recurrence set is generated by gathering all of the
  start DATE-TIME values generated by any of the specified "RRULE"
  and "RDATE" properties, and then excluding any start DATE-TIME
  values specified by "EXDATE" properties.  This implies that start
  DATE-TIME values specified by "EXDATE" properties take precedence
  over those specified by inclusion properties (i.e., "RDATE" and
  "RRULE").  Where duplicate instances are generated by the "RRULE"
  and "RDATE" properties, only one recurrence is considered.
  Duplicate instances are ignored.

这意味着您可以有一个startdate(DTSTART)和一个递归规则(RRULE)。通过使用EXDATE,你可以制作一个RRULE,上面写着“从STARTDATE到ENDDATE的每一天,除了[你不想要的所有小时的列表]”。这只适用于每天,您不能按照标准每小时召开一次会议

我使用RDATE解决了我的问题:

event = {'summary': 'Voluntariado Grandes Amigos',
    'description': 'TEST', 
    'start': {'dateTime': '2021-02-07T17:30:00',
            'timeZone': 'America/Mexico_City'},
    'end': {'dateTime': '2021-02-07T18:00:00',
            'timeZone': 'America/Mexico_City'}, 
    'recurrence': ["RDATE;VALUE=DATE-TIME:20210207T190000,20210207T214500"],
    'attendees': [{'email': 'someEmail1@gmail.com',
                   'email': 'someEmail2@gmail.com'}],
    'reminders': {'useDefault': False, 'overrides': [{'method': 'email', 'minutes': 60}]},
     
}

它工作得很好,不过也欢迎任何其他建议或意见:)

相关问题 更多 >