我有以下代码,它将一个日历事件发布到 office 365 REST API 上的事件中。我需要在我的日历中输入大约 100 个事件。有什么方法可以在 json 数据中放置多个事件,还是应该使用 for 循环?
import urllib2
import getpass
import os
import json
import sys
import base64
# Set the request parameters
url = 'https://outlook.office365.com/api/v1.0/me/events?$Select=Start,End'
user = 'emailuser@email.com'
pwd = getpass.getpass('Please enter your AD password: ')
# Create JSON payload
data = {
"Subject": "My Subject",
"Body": {
"ContentType": "HTML",
"Content": ""
},
"Start": "2015-08-11T07:00:00-05:00",
"StartTimeZone": "Central Standard Time",
"End": "2015-08-11T15:00:00-05:00",
"EndTimeZone": "Central Standard Time",
}
json_payload = json.dumps(data)
# Build the HTTP request
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(url, data=json_payload)
auth = base64.encodestring('%s:%s' % (user, pwd)).replace('\n', '')
request.add_header('Authorization', 'Basic %s' % auth)
request.add_header('Content-Type', 'application/json')
request.add_header('Accept', 'application/json')
request.get_method = lambda: 'POST'
# Perform the request
result = opener.open(request)