【发布时间】:2021-01-24 16:58:47
【问题描述】:
我创建了一个 python 程序/脚本来帮助我从 google 表格文档中一次更新许多日历。它运行得非常整齐。
我还创建了一个函数,它将遍历所有感兴趣的日历并删除事件系列和类似事件。此功能似乎只适用于某些日历而不是全部。当我检查我的在线谷歌日历时,一些仍然没有删除事件和事件系列。当我打印出事件系列 json 时,它显示状态为“已取消”,我对此无能为力,只能转到它失败的每个日历并自己手动删除事件系列。
对此的任何帮助将不胜感激!!!!
我最近才开始使用整个 google api,所以我的代码中可能会遗漏一些东西。
def Delete_Events():
calendars=googleServices['Calendar'].calendarList().list().execute()
for calendar in calendars['items']:
if 'IAT' in calendar['summary'] or 'Possible' in calendar['summary']:
print(calendar['summary'])
gevents = googleServices['Calendar'].events().list(calendarId=calendar['id']).execute()
for gevent in gevents['items']:
try:
googleServices['Calendar'].events().delete(calendarId=calendar['id'], eventId=gevent['id']).execute()
time.sleep(2)
pass
except Exception as e:
print(e)
instances = googleServices['Calendar'].events().instances(calendarId=calendar['id'],eventId=gevent['id']).execute()
for instance in instances['items']:
print(instance['summary'])
try:
googleServices['Calendar'].events().delete(calendarId=calendar['id'], eventId=instance['recurringEventId']).execute()
time.sleep(2)
break
except Exception as e:
print(e)
break
这是我为事件打印出来的 json
{'kind': 'calendar#event', 'etag': '"3222549224124000"', 'id': 'm80coonp168fml4hec4tq777cc_20210101T130000Z', 'status': 'cancelled', 'recurringEventId': 'm80coonp168fml4hec4tq777cc', 'originalStartTime': {'dateTime': '2021-01-01T07:00:00-06:00', 'timeZone': 'America/Mexico_City'}}
这是我可以打印出来的实例 json
<HttpError 410 when requesting https://www.googleapis.com/calendar/v3/calendars/la2gtl3ih4r7o14aj7edhe1luc%40group.calendar.google.com/events/m80coonp168fml4hec4tq777cc_20210101T130000Z? returned "Resource has been deleted">
{'kind': 'calendar#event', 'etag': '"3222549224908000"', 'id': 'm80coonp168fml4hec4tq777cc_20210104T130000Z', 'status': 'cancelled', 'recurringEventId': 'm80coonp168fml4hec4tq777cc', 'originalStartTime': {'dateTime': '2021-01-04T07:00:00-06:00', 'timeZone': 'America/Mexico_City'}}
如您所见,两者都返回相同的 json 信息以及 410 错误,提到“资源已被删除”,这是不正确的,因为我仍然可以从我的谷歌日历中手动查看、编辑和删除它网络浏览器。
再一次,任何帮助都会很棒!
【问题讨论】:
-
你能举几个例子来说明会被删除和不会被删除的事件吗?它们的重复规则和日期将有利于繁殖
标签: python google-api google-calendar-api