在 office365 rest 中创建多个事件 api
Creating multiple events in office365 rest api
我有以下代码,可将一个日历事件发布到 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)
我最终制作了一次创建一个事件并在每次迭代中调用该函数的函数:
def create_event(date1, date2):
# Create JSON payload
data = {
"Subject": admin.longname,
"Body": {
"ContentType": "HTML",
"Content": ""
},
"Start": date1,
"StartTimeZone": "Central Standard Time",
"End": date2,
"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)
def A( weeka, weekb ):
today = datetime.date.today()
firstday = today + relativedelta(weekday=SU(+ weeka))
for i in range(5):
firstday += datetime.timedelta(days=1)
date1 = '%sT07:00:00-05:00' % firstday
date2 = '%sT16:00:00-05:00' % firstday
create_event(date1, date2)
A(1,2)
批处理在我们的路线图上,但今天没有。
我有以下代码,可将一个日历事件发布到 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)
我最终制作了一次创建一个事件并在每次迭代中调用该函数的函数:
def create_event(date1, date2):
# Create JSON payload
data = {
"Subject": admin.longname,
"Body": {
"ContentType": "HTML",
"Content": ""
},
"Start": date1,
"StartTimeZone": "Central Standard Time",
"End": date2,
"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)
def A( weeka, weekb ):
today = datetime.date.today()
firstday = today + relativedelta(weekday=SU(+ weeka))
for i in range(5):
firstday += datetime.timedelta(days=1)
date1 = '%sT07:00:00-05:00' % firstday
date2 = '%sT16:00:00-05:00' % firstday
create_event(date1, date2)
A(1,2)
批处理在我们的路线图上,但今天没有。