Skip to content

Commit c2ac3e4

Browse files
committed
Metodos de source y target tanto para eventos y calendarios, NO WEBHOOKS
1 parent ad0fb23 commit c2ac3e4

File tree

1 file changed

+93
-5
lines changed

1 file changed

+93
-5
lines changed

microsoftgraph/client.py

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,107 @@ def get_me_events(self):
216216
return False
217217
return event
218218

219-
def create_calendar_event(self):
219+
def create_calendar_event(
220+
self, subject, content,
221+
start_datetime, start_timezone, end_datetime,
222+
end_timezone, recurrence_type, recurrence_interval,
223+
recurrence_days_of_week, recurrence_range_type,
224+
recurrence_range_startdate, recurrence_range_enddate,
225+
location, attendees):
220226
"""
221-
Create an event in user calendar.
222-
:return:
227+
TODO: manual testing
228+
Create a new calendar event.
229+
Args:
230+
subject: subject of event, string
231+
content: content of event, string
232+
start_datetime: in the format of 2017-09-04T11:00:00, dateTimeTimeZone string
233+
start_timezone: in the format of Pacific Standard Time, string
234+
end_datetime: in the format of 2017-09-04T11:00:00, dateTimeTimeZone string
235+
end_timezone: in the format of Pacific Standard Time, string
236+
recurrence_type: daily, weekly, absoluteMonthly, relativeMonthly, absoluteYearly, relativeYearly
237+
recurrence_interval: The number of units between occurrences, can be in days, weeks, months, or years,
238+
depending on the type. Required.
239+
recurrence_days_of_week: sunday, monday, tuesday, wednesday, thursday, friday, saturday
240+
recurrence_range_type: endDate, noEnd, numbered
241+
recurrence_range_startdate: The date to start applying the recurrence pattern. The first occurrence of the
242+
meeting may be this date or later, depending on the recurrence pattern of the
243+
event. Must be the same value as the start property of the recurring event.
244+
Required.
245+
recurrence_range_enddate: Required if type is endDate, The date to stop applying the recurrence pattern.
246+
Depending on the recurrence pattern of the event, the last occurrence of the
247+
meeting may not be this date.
248+
location: string
249+
attendees: list of dicts of the form:
250+
{"emailAddress": {"address": a['attendees_email'],"name": a['attendees_name']}
251+
252+
Returns:
253+
223254
"""
224-
body = {}
255+
attendees_list = [{
256+
"emailAddress": {
257+
"address": a['attendees_email'],
258+
"name": a['attendees_name']
259+
},
260+
"type": a['attendees_type']
261+
} for a in attendees]
262+
body = {
263+
"subject": subject,
264+
"body": {
265+
"contentType": "HTML",
266+
"content": content
267+
},
268+
"start": {
269+
"dateTime": start_datetime,
270+
"timeZone": start_timezone
271+
},
272+
"end": {
273+
"dateTime": end_datetime,
274+
"timeZone": end_timezone
275+
},
276+
"recurrence": {
277+
"pattern": {
278+
"type": recurrence_type,
279+
"interval": recurrence_interval,
280+
"daysOfWeek": recurrence_days_of_week
281+
},
282+
"range": {
283+
"type": recurrence_range_type,
284+
"startDate": recurrence_range_startdate,
285+
"endDate": recurrence_range_enddate
286+
}
287+
},
288+
"location": {
289+
"displayName": location
290+
},
291+
"attendees": attendees_list
292+
}
293+
225294
try:
226-
response = self._post('me/events')
295+
response = self._post('me/events', json=body)
227296
print('---> ', response)
228297
except Exception as e:
229298
print("Error donwloading data: ", e)
230299
return False
231300

301+
def create_calendar(self, name):
302+
"""
303+
Created a new calendar.
304+
Args:
305+
name: name of new calendar to be created, string.
306+
307+
Returns:
308+
309+
"""
310+
body = {
311+
'name': '{}'.format(name)
312+
}
313+
try:
314+
response = self._post('me/calendars', json=body)
315+
return response
316+
except Exception as e:
317+
print('Error while creating calendar: ', e)
318+
return False
319+
232320
def get_me_calendar(self, id_cal=None):
233321
"""
234322
TODO: manual test.

0 commit comments

Comments
 (0)