0
非常感谢您花时间帮助!在插入事件之前插入新日历Google API和删除日历事件(Python)
我创建一个Python脚本,我需要做到以下几点:
- 创建一个新的日历;如果需要的话
我无法将新日历插入到完整日历中。 我已浏览Google日历资源,但似乎无法遵循它。我的代码现在如下:
注:因为我不知道如何插入一个新的日历,事件正在编码进入主日历
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
try:
import argparse
flags = argparse.ArgumentParser(parents
[tools.argparser]).parse_args()
except ImportError:
flags = None
SCOPES = 'https://www.googleapis.com/auth/calendar'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store, flags) \
if flags else tools.run(flow, store)
CAL = build('calendar', 'v3', http=creds.authorize(Http()))
GMT_OFF = '-04:00' # ET/MST/GMT-4
EVENT = {
'summary': 'Find venue',
'start': {'dateTime': '2017-06-23T13:00:00%s' % GMT_OFF},
'end': {'dateTime': '2017-06-23T14:00:00%s' % GMT_OFF},
}
EVENT2 = {
'summary': 'Visit museum',
'start': {'dateTime': '2017-07-09T13:00:00%s' % GMT_OFF},
'end': {'dateTime': '2017-07-09T14:00:00%s' % GMT_OFF},
}
EVENT3 = {
'summary': 'Buy fruits',
'start': {'dateTime': '2017-07-23T13:00:00%s' % GMT_OFF},
'end': {'dateTime': '2017-07-23T14:00:00%s' % GMT_OFF},
}
e = CAL.events().insert(calendarId='primary',
sendNotifications=True, body=EVENT).execute()
e = CAL.events().insert(calendarId='primary',
sendNotifications=True, body=EVENT2).execute()
e = CAL.events().insert(calendarId='primary',
sendNotifications=True, body=EVENT3).execute()
print('''*** %r event added:
Start: %s
End: %s''' % (e['summary'].encode('utf-8'),
e['start']['dateTime'], e['end']['dateTime']))
所以,在Calendar事件插入,我想插入一个名为'XYZ'的新日历。然后,编码的以下事件将被添加到'XYZ'。另外,我想添加能够在用户请求时从完整的Gmail中删除日历“XYZ”。
再次感谢您的帮助!让我知道,如果我能提供更清晰。