Skip to content

Commit 3c85591

Browse files
committed
2 parents 816878b + c2ac3e4 commit 3c85591

File tree

1 file changed

+203
-0
lines changed

1 file changed

+203
-0
lines changed

microsoftgraph/client.py

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,209 @@ def delete_subscription(self, subscription_id):
171171
"""
172172
return self._delete('https://graph.microsoft.com/beta/' + 'subscriptions/{}'.format(subscription_id))
173173

174+
def get_me_events(self):
175+
"""
176+
Obtiene los eventos del usuario
177+
:return: dictionary of events.
178+
"""
179+
try:
180+
response = self._get('me/events')
181+
except Exception as e:
182+
return False
183+
try:
184+
event = {
185+
'attendees': '{}'.format(response['value']['attendees']),
186+
'categories': '{}'.format(response['value']['categories']),
187+
'created': '{}'.format(response['value']['createdDateTime']),
188+
'end': '{0}-TZ-{1} '.format(response['value']['end']['dateTime'], response['value']['end']['timeZone']),
189+
'hasAttachments': '{}'.format(response['value']['hasAttachments']),
190+
'iCalId': '{}'.format(response['value']['iCalId']),
191+
'id': '{}'.format(response['value']['id']),
192+
'importance': '{}'.format(response['value']['importance']),
193+
'All Day': '{}'.format(response['value']['isAllDay']),
194+
'cancelled': '{}'.format(response['value']['isCancelled']),
195+
'isOrganizer': '{}'.format(response['value']['isOrganizer']),
196+
'is reminder on': '{}'.format(response['value']['isReminderOn']),
197+
'last modification': '{}'.format(response['value']['lastModifiedDateTime']),
198+
'location': '{}'.format(response['value']['location']['address']),
199+
'online Meeting Url': '{}'.format(response['value']['onlineMeetingUrl']),
200+
'organizer name': '{}'.format(response['value']['emailAddress']['name']),
201+
'organizer email': '{}'.format(response['value']['emailAddress']['address']),
202+
'original End TimeZone': '{}'.format(response['value']['originalEndTimeZone']),
203+
'original Start TimeZone': '{}'.format(response['value']['originalStartTimeZone']),
204+
'recurrence': '{}'.format(response['value']['recurrence']),
205+
'reminderMinutesBeforeStart': '{}'.format(response['value']['reminderMinutesBeforeStart']),
206+
'response Requested': '{}'.format(response['value']['responseRequested']),
207+
'response Status': '{}'.format(response['value']['responseStatus']),
208+
'sensitivity': '{}'.format(response['value']['sensitivity']),
209+
'series Master Id': '{}'.format(response['value']['seriesMasterId']),
210+
'show As': '{}'.format(response['value']['showAs']),
211+
'start': '{0}-TZ-{1} '.format(
212+
response['value']['start']['dateTime'], response['value']['start']['timeZone']),
213+
'subject': '{}'.format(response['value']['subject']),
214+
'type': '{}'.format(response['value']['type']),
215+
'webLink': '{}'.format(response['value']['webLink']),
216+
}
217+
except Exception as e:
218+
print('Error while formatting downloaded data: ', e)
219+
return False
220+
return event
221+
222+
def create_calendar_event(
223+
self, subject, content,
224+
start_datetime, start_timezone, end_datetime,
225+
end_timezone, recurrence_type, recurrence_interval,
226+
recurrence_days_of_week, recurrence_range_type,
227+
recurrence_range_startdate, recurrence_range_enddate,
228+
location, attendees):
229+
"""
230+
TODO: manual testing
231+
Create a new calendar event.
232+
Args:
233+
subject: subject of event, string
234+
content: content of event, string
235+
start_datetime: in the format of 2017-09-04T11:00:00, dateTimeTimeZone string
236+
start_timezone: in the format of Pacific Standard Time, string
237+
end_datetime: in the format of 2017-09-04T11:00:00, dateTimeTimeZone string
238+
end_timezone: in the format of Pacific Standard Time, string
239+
recurrence_type: daily, weekly, absoluteMonthly, relativeMonthly, absoluteYearly, relativeYearly
240+
recurrence_interval: The number of units between occurrences, can be in days, weeks, months, or years,
241+
depending on the type. Required.
242+
recurrence_days_of_week: sunday, monday, tuesday, wednesday, thursday, friday, saturday
243+
recurrence_range_type: endDate, noEnd, numbered
244+
recurrence_range_startdate: The date to start applying the recurrence pattern. The first occurrence of the
245+
meeting may be this date or later, depending on the recurrence pattern of the
246+
event. Must be the same value as the start property of the recurring event.
247+
Required.
248+
recurrence_range_enddate: Required if type is endDate, The date to stop applying the recurrence pattern.
249+
Depending on the recurrence pattern of the event, the last occurrence of the
250+
meeting may not be this date.
251+
location: string
252+
attendees: list of dicts of the form:
253+
{"emailAddress": {"address": a['attendees_email'],"name": a['attendees_name']}
254+
255+
Returns:
256+
257+
"""
258+
attendees_list = [{
259+
"emailAddress": {
260+
"address": a['attendees_email'],
261+
"name": a['attendees_name']
262+
},
263+
"type": a['attendees_type']
264+
} for a in attendees]
265+
body = {
266+
"subject": subject,
267+
"body": {
268+
"contentType": "HTML",
269+
"content": content
270+
},
271+
"start": {
272+
"dateTime": start_datetime,
273+
"timeZone": start_timezone
274+
},
275+
"end": {
276+
"dateTime": end_datetime,
277+
"timeZone": end_timezone
278+
},
279+
"recurrence": {
280+
"pattern": {
281+
"type": recurrence_type,
282+
"interval": recurrence_interval,
283+
"daysOfWeek": recurrence_days_of_week
284+
},
285+
"range": {
286+
"type": recurrence_range_type,
287+
"startDate": recurrence_range_startdate,
288+
"endDate": recurrence_range_enddate
289+
}
290+
},
291+
"location": {
292+
"displayName": location
293+
},
294+
"attendees": attendees_list
295+
}
296+
297+
try:
298+
response = self._post('me/events', json=body)
299+
print('---> ', response)
300+
except Exception as e:
301+
print("Error donwloading data: ", e)
302+
return False
303+
304+
def create_calendar(self, name):
305+
"""
306+
Created a new calendar.
307+
Args:
308+
name: name of new calendar to be created, string.
309+
310+
Returns:
311+
312+
"""
313+
body = {
314+
'name': '{}'.format(name)
315+
}
316+
try:
317+
response = self._post('me/calendars', json=body)
318+
return response
319+
except Exception as e:
320+
print('Error while creating calendar: ', e)
321+
return False
322+
323+
def get_me_calendar(self, id_cal=None):
324+
"""
325+
TODO: manual test.
326+
Specific calendar.
327+
:return:
328+
"""
329+
url = 'me/calendar/{}'.format(id_cal) if id_cal is not None else 'me/calendar'
330+
try:
331+
response = self._get(url)
332+
print('---> ', response)
333+
except Exception as e:
334+
print("Error donwloading data: ", e)
335+
return False
336+
try:
337+
return [{
338+
'id': c['id'],
339+
'canEdit': c['canEdit'],
340+
'canShare': c['canShare'],
341+
'canViewPrivateItems': c['canViewPrivateItems'],
342+
'changeKey': c['changeKey'],
343+
'color': c['color'],
344+
'name': c['name'],
345+
'owner': '{0}-{1}'.format(c['owner']['name'], c['owner']['address']),
346+
} for c in response['value']]
347+
except Exception as e:
348+
print('Error formating downloaded data: ', e)
349+
return False
350+
351+
def get_me_calendars(self):
352+
"""
353+
All the calendars of user.
354+
:return:
355+
"""
356+
try:
357+
response = self._get('me/calendars')
358+
print('---> ', response)
359+
except Exception as e:
360+
print('Error downloading data: ', e)
361+
return False
362+
try:
363+
return [{
364+
'id': c['id'],
365+
'name': c['name'],
366+
'color': c['color'],
367+
'changeKey': c['changeKey'],
368+
'canShare': c['canShare'],
369+
'canViewPrivateItems': c['canViewPrivateItems'],
370+
'canEdit': c['canEdit'],
371+
'owner': c['canEdit'],
372+
} for c in response['value']]
373+
except Exception as e:
374+
print('Error formating downloaded data: ', e)
375+
return False
376+
174377
def send_mail(self, subject=None, recipients=None, body='', content_type='HTML', attachments=None):
175378
"""Helper to send email from current user.
176379

0 commit comments

Comments
 (0)