1
1
import logging
2
- from datetime import datetime
3
2
4
3
5
4
logger = logging .getLogger (__name__ )
6
5
7
- date_format = '%Y-%m-%d'
8
- datetime_format = date_format + 'T%H:%M:%S'
9
- full_datetime_format = date_format + 'T%H:%M:%S.%f'
10
- extended_datetime_format = date_format + 'T%H:%M:%S.%fZ'
11
6
12
-
13
- def parse_date_times (text ):
14
- instance = None
15
- for format in [extended_datetime_format , full_datetime_format , datetime_format , date_format ]:
16
- try :
17
- instance = datetime .strptime (text , format )
18
- except Exception :
19
- pass
20
- else :
21
- break
22
- return instance
23
-
24
-
25
- class Calendar (object ):
7
+ class Calendar (base .Base )
26
8
__slots__ = ('id' , 'name' , 'owner' , 'color' , 'can_edit' , 'can_share' , 'can_view_private_items' , 'change_key' )
27
9
28
10
def __init__ (self , id , name , owner , color , can_edit , can_share , can_view_private_items , change_key ):
@@ -136,7 +118,7 @@ def get(cls, api, **kwargs):
136
118
return output
137
119
138
120
139
- class Location (object ):
121
+ class Location (base . Base )
140
122
__slots__ = ('display_name' , 'location_type' , 'unique_id' , 'unique_id_type' )
141
123
142
124
def __init__ (self , display_name , location_type , unique_id , unique_id_type ):
@@ -160,7 +142,7 @@ def from_api(cls, data):
160
142
return cls (display_name , location_type , unique_id , unique_id_type )
161
143
162
144
163
- class Attendee (object ):
145
+ class Attendee (base . Base )
164
146
__slots__ = ('name' , 'email_address' , 'type' , 'status' , 'response_time' )
165
147
166
148
def __init__ (self , name , email_address , type , status , response_time ):
@@ -188,11 +170,11 @@ def from_api(cls, data):
188
170
status = status_data .get ('response' )
189
171
response_time = status_data .get ('time' )
190
172
if response_time :
191
- response_time = parse_date_times (response_time )
173
+ response_time = cls . parse_date_time (response_time )
192
174
return cls (name , email_address , type , status , response_time )
193
175
194
176
195
- class Category (object ):
177
+ class Category (base . Base )
196
178
__slots__ = ('id' , 'display_name' , 'color' )
197
179
198
180
def __init__ (self , id , display_name , color ):
@@ -313,7 +295,7 @@ def create(cls, api, display_name, color, **kwargs):
313
295
return instance
314
296
315
297
316
- class Range (object ):
298
+ class Range (base . Base )
317
299
__slots__ = ('type' , 'start_date' , 'end_date' )
318
300
319
301
def __init__ (self , type , start_date , end_date ):
@@ -325,19 +307,19 @@ def __repr__(self):
325
307
return '<%s %s type=%r start_date=%r, end_date=%r>' % (self .__class__ .__name__ , id (self ), self .type , self .start_date , self .end_date )
326
308
327
309
def to_dict (self ):
328
- start_date = self .start_date .strftime (date_format )
329
- end_date = self .end_date .strftime (date_format )
310
+ start_date = self .start_date .strftime (self . date_format )
311
+ end_date = self .end_date .strftime (self . date_format )
330
312
return dict (type = type , startDate = start_date , endDate = end_date )
331
313
332
314
@classmethod
333
315
def from_api (cls , data ):
334
316
type = data ['type' ]
335
- start_date = parse_date_times (data ['startDate' ])
336
- end_date = parse_date_times (data ['endDate' ])
317
+ start_date = cls . parse_date_time (data ['startDate' ])
318
+ end_date = cls . parse_date_time (data ['endDate' ])
337
319
return cls (type , start_date , end_date )
338
320
339
321
340
- class DateTime (object ):
322
+ class DateTime (base . Base )
341
323
__slots__ = ('date_time' , 'time_zone' )
342
324
343
325
def __init__ (self , date_time , time_zone ):
@@ -348,19 +330,19 @@ def __repr__(self):
348
330
return '<%s %s date_time=%r, time_zone=%r>' % (self .__class__ .__name__ , id (self ), self .date_time , self .time_zone )
349
331
350
332
def to_dict (self ):
351
- date_time = self .date_time .strftime (datetime_format )
333
+ date_time = self .date_time .strftime (self . datetime_format )
352
334
time_zone = self .time_zone
353
335
return dict (dateTime = date_time , timeZone = time_zone )
354
336
355
337
@classmethod
356
338
def from_api (cls , data ):
357
339
date_time = data ['dateTime' ]
358
- date_time = parse_date_times (date_time [:26 ])
340
+ date_time = cls . parse_date_time (date_time [:26 ])
359
341
time_zone = data ['timeZone' ]
360
342
return cls (date_time , time_zone )
361
343
362
344
363
- class Event (object ):
345
+ class Event (base . Base )
364
346
__slots__ = ('id' , 'ical_uid' , 'series_master_id' , 'type' , 'categories' , 'subject' , 'body' , 'body_preview' , 'attendees' , 'locations' , 'location' , 'start' , 'original_start' , 'original_start_time_zone' , 'end' , 'original_end' , 'original_end_time_zone' , 'is_all_day' , 'is_cancelled' , 'is_reminder_on' , 'is_organizer' , 'organizer' , 'importance' , 'sensitivity' , 'recurrence' , 'response_requested' , 'response_status' , 'reminder_minutes_before_start' , 'show_as' , 'online_meeting_url' , 'web_link' , 'has_attachments' , 'attachments' , 'calendar' , 'extensions' , 'instances' , 'multi_value_extended_properties' , 'single_value_extended_properties' , 'created_at' , 'last_modified' , 'removed' )
365
347
366
348
def __init__ (self , id , ical_uid , series_master_id , type , categories , subject , body , body_preview , attendees , locations , location , start , original_start , original_start_time_zone , end , original_end , original_end_time_zone , is_all_day , is_cancelled , is_reminder_on , is_organizer , organizer , importance , sensitivity , recurrence , response_requested , response_status , reminder_minutes_before_start , show_as , online_meeting_url , web_link , has_attachments , attachments , calendar , extensions , instances , multi_value_extended_properties , single_value_extended_properties , created_at , last_modified , removed ):
@@ -522,12 +504,12 @@ def from_api(cls, data):
522
504
start = DateTime .from_api (data ['start' ])
523
505
original_start = data .get ('originalStart' )
524
506
if original_start :
525
- original_start = parse_date_times (original_start [:26 ])
507
+ original_start = cls . parse_date_time (original_start [:26 ])
526
508
original_start_time_zone = data .get ('originalStartTimeZone' )
527
509
end = DateTime .from_api (data ['end' ])
528
510
original_end = data .get ('originalEnd' )
529
511
if original_end :
530
- original_end = parse_date_times (original_end [:26 ])
512
+ original_end = cls . parse_date_time (original_end [:26 ])
531
513
original_end_time_zone = data .get ('originalEndTimeZone' )
532
514
is_all_day = data ['isAllDay' ]
533
515
is_cancelled = data ['isCancelled' ]
@@ -553,8 +535,8 @@ def from_api(cls, data):
553
535
instances = data .get ('instances' , [])
554
536
multi_value_extended_properties = data .get ('multiValueEextendedProperties' , [])
555
537
single_value_extended_properties = data .get ('singleValueExtendedProperties' , [])
556
- created_at = parse_date_times (data ['createdDateTime' ][:26 ])
557
- last_modified = parse_date_times (data ['lastModifiedDateTime' ][:26 ])
538
+ created_at = cls . parse_date_time (data ['createdDateTime' ][:26 ])
539
+ last_modified = cls . parse_date_time (data ['lastModifiedDateTime' ][:26 ])
558
540
removed = data .get ('@removed' )
559
541
return cls (id , ical_uid , series_master_id , type , categories , subject , body , body_preview , attendees , locations , location , start , original_start , original_start_time_zone , end , original_end , original_end_time_zone , is_all_day , is_cancelled , is_reminder_on , is_organizer , organizer , importance , sensitivity , recurrence , response_requested , response_status , reminder_minutes_before_start , show_as , online_meeting_url , web_link , has_attachments , attachments , calendar , extensions , instances , multi_value_extended_properties , single_value_extended_properties , created_at , last_modified , removed )
560
542
@@ -579,8 +561,8 @@ def delta(cls, api, start, end, **kwargs):
579
561
"""
580
562
fields = kwargs .get ('fields' , ['id' , 'seriesMasterId' , 'type' , 'categories' , 'subject' , 'body' , 'bodyPreview' , 'attendees' , 'locations' , 'location' , 'start' , 'end' , 'isAllDay' , 'isCancelled' , 'isReminderOn' , 'isOrganizer' , 'originalStart' , 'originalStartTimeZone' , 'originalEndTimeZone' , 'organizer' , 'importance' , 'sensitivity' , 'recurrence' , 'responseRequested' , 'responseStatus' , 'reminderMinutesBeforeStart' , 'showAs' , 'onlineMeetingUrl' , 'webLink' , 'hasAttachments' , 'attachments' , 'calendar' , 'extensions' , 'instances' , 'createdDateTime' , 'lastModifiedDateTime' ])
581
563
user = kwargs .get ('user' )
582
- start_formatted = start .strftime (datetime_format )
583
- end_formatted = end .strftime (datetime_format )
564
+ start_formatted = start .strftime (cls . datetime_format )
565
+ end_formatted = end .strftime (cls . datetime_format )
584
566
if user :
585
567
uri = 'users/%s/calendarView/delta' % user
586
568
else :
@@ -689,7 +671,7 @@ def create(cls, api, subject, body, **kwargs):
689
671
sensitivity (str): Sensitivity of the Event. Possible values are: normal, personal, private, confidential
690
672
recurrence (dict): The recurrence pattern for the Event
691
673
response_requested (bool): Indicates if potential attendees need to respond
692
- response_status (object): Indicates the type of response sent in response to an event message.
674
+ response_status (base.Base) Indicates the type of response sent in response to an event message.
693
675
reminder_minutes_before_start (int): The number of minutes before the event start time that the reminder alert occurs.
694
676
show_as (str): The status to show for the User during the Event
695
677
"""
@@ -737,7 +719,7 @@ def create(cls, api, subject, body, **kwargs):
737
719
return instance
738
720
739
721
740
- class Group (object ):
722
+ class Group (base . Base )
741
723
__slots__ = ('id' , 'name' , 'class_id' , 'change_key' )
742
724
743
725
def __init__ (self , id , name , class_id , change_key ):
@@ -856,7 +838,7 @@ def create(cls, api, name, class_id, change_key, **kwargs):
856
838
return instance
857
839
858
840
859
- class Attachment (object ):
841
+ class Attachment (base . Base )
860
842
"""
861
843
Attachment instance representing a file attachment to an Event
862
844
@@ -886,14 +868,14 @@ def __repr__(self):
886
868
return '<%s %s id=%r, name=%r, is_inline=%s, size=%r, last_modified_datetime=%r>' % (self .__class__ .__name__ , id (self ), self .id , self .name , self .is_inline , self .size , self .last_modified_datetime )
887
869
888
870
@classmethod
889
- def from_api (self , data ):
871
+ def from_api (cls , data ):
890
872
id = data ['id' ]
891
873
name = data ['name' ]
892
874
is_inline = data ['isInline' ]
893
875
size = data ['size' ]
894
876
raw_last_modified_datetime = data ['lastModifiedDateTime' ]
895
877
if raw_last_modified_datetime :
896
- last_modified_datetime = datetime . strptime (raw_last_modified_datetime [:- 1 ], datetime_format )
878
+ last_modified_datetime = cls . parse_date_time (raw_last_modified_datetime [:- 1 ])
897
879
return cls (id , name , is_inline , size , content_id , content_type , content_location , content_bytes , last_modified_datetime )
898
880
899
881
@classmethod
@@ -1003,7 +985,7 @@ def from_api(cls, data):
1003
985
content_location = data ['contentLocation' ]
1004
986
content_bytes = data ['contentBytes' ]
1005
987
if raw_last_modified_datetime :
1006
- last_modified_datetime = datetime . strptime (raw_last_modified_datetime [:- 1 ], datetime_format )
988
+ last_modified_datetime = cls . parse_date_time (raw_last_modified_datetime [:- 1 ])
1007
989
return cls (id , name , is_inline , size , content_id , content_type , content_location , content_bytes , last_modified_datetime )
1008
990
1009
991
@classmethod
0 commit comments