From b3867fba5b4f16af7e1a362886384d659c073164 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Mon, 3 Mar 2025 17:42:42 -0800 Subject: [PATCH] Fixed bug in `gam calendars info events` and `gam info events --- src/GamUpdate.txt | 5 +++++ src/gam/__init__.py | 40 +++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/GamUpdate.txt b/src/GamUpdate.txt index ee1ef246..cfe5aac7 100644 --- a/src/GamUpdate.txt +++ b/src/GamUpdate.txt @@ -1,3 +1,8 @@ +7.05.07 + +Fixed bug in `gam calendars info events` and `gam info events` +where option `showdayofweek` was not recognized. + 7.05.06 Improve message displayed when a command is issued that requires Google Chat Bot setup; diff --git a/src/gam/__init__.py b/src/gam/__init__.py index e1acb0ce..cbf19ad7 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki """ __author__ = 'GAM Team ' -__version__ = '7.05.06' +__version__ = '7.05.07' __license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)' #pylint: disable=wrong-import-position @@ -38938,6 +38938,22 @@ def _setEventRecurrenceTimeZone(cal, calId, body, parameters, i, count): body['end']['timeZone'] = timeZone return True +def _getEventDaysOfWeek(event): + for attr in ['start', 'end']: + if attr in event: + if 'date' in event[attr]: + try: + dateTime = datetime.datetime.strptime(event[attr]['date'], YYYYMMDD_FORMAT) + event[attr]['dayOfWeek'] = calendarlib.day_abbr[dateTime.weekday()] + except ValueError: + pass + elif 'dateTime' in event[attr]: + try: + dateTime, _ = iso8601.parse_date(event[attr]['dateTime']) + event[attr]['dayOfWeek'] = calendarlib.day_abbr[dateTime.weekday()] + except (iso8601.ParseError, OverflowError): + pass + def _createCalendarEvents(user, origCal, function, calIds, count, body, parameters): if parameters['attendees']: body['attendees'] = parameters.pop('attendees') @@ -39573,6 +39589,8 @@ def _getCalendarInfoEventOptions(calendarEventEntity): myarg = getArgument() if myarg == 'fields': _getEventFields(fieldsList) + elif myarg == 'showdayofweek': + calendarEventEntity['showDayOfWeek'] = True else: FJQC.GetFormatJSON(myarg) _addEventEntitySelectFields(calendarEventEntity, fieldsList) @@ -39596,6 +39614,8 @@ def _infoCalendarEvents(origUser, user, origCal, calIds, count, calendarEventEnt throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.NOT_FOUND, GAPI.DELETED, GAPI.FORBIDDEN], calendarId=calId, eventId=eventId, fields=fields) if calendarEventEntity['maxinstances'] == -1 or 'recurrence' not in event: + if calendarEventEntity['showDayOfWeek']: + _getEventDaysOfWeek(event) _showCalendarEvent(user, calId, Ent.EVENT, event, j, jcount, FJQC) else: instances = callGAPIpages(cal.events(), 'instances', 'items', @@ -39609,6 +39629,8 @@ def _infoCalendarEvents(origUser, user, origCal, calIds, count, calendarEventEnt l = 0 for instance in instances: l += 1 + if calendarEventEntity['showDayOfWeek']: + _getEventDaysOfWeek(instance) _showCalendarEvent(user, calId, Ent.INSTANCE, instance, l, lcount, FJQC) Ind.Decrement() except (GAPI.notFound, GAPI.deleted) as e: @@ -39662,22 +39684,6 @@ def _getCalendarPrintShowEventOptions(calendarEventEntity, entityType): _addEventEntitySelectFields(calendarEventEntity, fieldsList) return (csvPF, FJQC, fieldsList) -def _getEventDaysOfWeek(event): - for attr in ['start', 'end']: - if attr in event: - if 'date' in event[attr]: - try: - dateTime = datetime.datetime.strptime(event[attr]['date'], YYYYMMDD_FORMAT) - event[attr]['dayOfWeek'] = calendarlib.day_abbr[dateTime.weekday()] - except ValueError: - pass - elif 'dateTime' in event[attr]: - try: - dateTime, _ = iso8601.parse_date(event[attr]['dateTime']) - event[attr]['dayOfWeek'] = calendarlib.day_abbr[dateTime.weekday()] - except (iso8601.ParseError, OverflowError): - pass - # gam calendars print events * # [fields ] [showdayofweek] # [countsonly] [formatjson [quotechar ]] [todrive *]