Skip to content

Commit 54d9090

Browse files
committed
Metodos de Outllok
1 parent 02c8f99 commit 54d9090

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

microsoftgraph/client.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def set_token(self, token):
107107
"""
108108
self.token = token
109109

110+
<<<<<<< Updated upstream
110111
def get_me(self, params=None):
111112
"""Retrieve the properties and relationships of user object.
112113
@@ -167,6 +168,130 @@ def send_mail(self, subject=None, recipients=None, body='', content_type='HTML',
167168

168169
def _get_headers(self):
169170
return {'Authorization': 'Bearer ' + self.token['access_token']}
171+
=======
172+
def get_me(self):
173+
"""
174+
Obtiene el "profile" del usuario
175+
:return: dictionary of user profile.
176+
"""
177+
return self._get('me')
178+
>>>>>>> Stashed changes
179+
180+
def get_me_events(self):
181+
"""
182+
Obtiene los eventos del usuario
183+
:return: dictionary of events.
184+
"""
185+
try:
186+
response = self._get('me/events')
187+
except Exception as e:
188+
return False
189+
try:
190+
event = {
191+
'attendees': '{}'.format(response['value']['attendees']),
192+
'categories': '{}'.format(response['value']['categories']),
193+
'created': '{}'.format(response['value']['createdDateTime']),
194+
'end': '{0}-TZ-{1} '.format(response['value']['end']['dateTime'], response['value']['end']['timeZone']),
195+
'hasAttachments': '{}'.format(response['value']['hasAttachments']),
196+
'iCalId': '{}'.format(response['value']['iCalId']),
197+
'id': '{}'.format(response['value']['id']),
198+
'importance': '{}'.format(response['value']['importance']),
199+
'All Day': '{}'.format(response['value']['isAllDay']),
200+
'cancelled': '{}'.format(response['value']['isCancelled']),
201+
'isOrganizer': '{}'.format(response['value']['isOrganizer']),
202+
'is reminder on': '{}'.format(response['value']['isReminderOn']),
203+
'last modification': '{}'.format(response['value']['lastModifiedDateTime']),
204+
'location': '{}'.format(response['value']['location']['address']),
205+
'online Meeting Url': '{}'.format(response['value']['onlineMeetingUrl']),
206+
'organizer name': '{}'.format(response['value']['emailAddress']['name']),
207+
'organizer email': '{}'.format(response['value']['emailAddress']['address']),
208+
'original End TimeZone': '{}'.format(response['value']['originalEndTimeZone']),
209+
'original Start TimeZone': '{}'.format(response['value']['originalStartTimeZone']),
210+
'recurrence': '{}'.format(response['value']['recurrence']),
211+
'reminderMinutesBeforeStart': '{}'.format(response['value']['reminderMinutesBeforeStart']),
212+
'response Requested': '{}'.format(response['value']['responseRequested']),
213+
'response Status': '{}'.format(response['value']['responseStatus']),
214+
'sensitivity': '{}'.format(response['value']['sensitivity']),
215+
'series Master Id': '{}'.format(response['value']['seriesMasterId']),
216+
'show As': '{}'.format(response['value']['showAs']),
217+
'start': '{0}-TZ-{1} '.format(
218+
response['value']['start']['dateTime'], response['value']['start']['timeZone']),
219+
'subject': '{}'.format(response['value']['subject']),
220+
'type': '{}'.format(response['value']['type']),
221+
'webLink': '{}'.format(response['value']['webLink']),
222+
}
223+
except Exception as e:
224+
print('Error while formatting downloaded data: ', e)
225+
return False
226+
return event
227+
228+
def create_calendar_event(self):
229+
"""
230+
Create an event in user calendar.
231+
:return:
232+
"""
233+
body = {}
234+
try:
235+
response = self._post('me/events')
236+
print('---> ', response)
237+
except Exception as e:
238+
print("Error donwloading data: ", e)
239+
return False
240+
241+
def get_me_calendar(self, id_cal=None):
242+
"""
243+
TODO: manual test.
244+
Specific calendar.
245+
:return:
246+
"""
247+
url = 'me/calendar/{}'.format(id_cal) if id_cal is not None else 'me/calendar'
248+
try:
249+
response = self._get(url)
250+
print('---> ', response)
251+
except Exception as e:
252+
print("Error donwloading data: ", e)
253+
return False
254+
try:
255+
return [{
256+
'id': c['id'],
257+
'canEdit': c['canEdit'],
258+
'canShare': c['canShare'],
259+
'canViewPrivateItems': c['canViewPrivateItems'],
260+
'changeKey': c['changeKey'],
261+
'color': c['color'],
262+
'name': c['name'],
263+
'owner': '{0}-{1}'.format(c['owner']['name'], c['owner']['address']),
264+
} for c in response['value']]
265+
except Exception as e:
266+
print('Error formating downloaded data: ', e)
267+
return False
268+
269+
def get_me_calendars(self):
270+
"""
271+
All the calendars of user.
272+
:return:
273+
"""
274+
try:
275+
response = self._get('me/calendars')
276+
print('---> ', response)
277+
except Exception as e:
278+
print('Error downloading data: ', e)
279+
return False
280+
try:
281+
return [{
282+
'id': c['id'],
283+
'name': c['name'],
284+
'color': c['color'],
285+
'changeKey': c['changeKey'],
286+
'canShare': c['canShare'],
287+
'canViewPrivateItems': c['canViewPrivateItems'],
288+
'canEdit': c['canEdit'],
289+
'owner': c['canEdit'],
290+
'canEdit': c['canEdit'],
291+
} for c in response['value']]
292+
except Exception as e:
293+
print('Error formating downloaded data: ', e)
294+
return False
170295

171296
def _get(self, endpoint, params=None):
172297
response = requests.get(self.base_url + endpoint, params=params, headers=self._get_headers())

0 commit comments

Comments
 (0)