insanum / gcalcli

Google Calendar Command Line Interface
MIT License
3.26k stars 307 forks source link

--nodeclined throws an error #620

Open lightheaded opened 2 years ago

lightheaded commented 2 years ago

I'm getting an error when trying to exclude declined events from the agenda.

~> gcalcli agenda --nodeclined                                                                                     1
Thu Nov 18  8:00           No-meeting zone
Traceback (most recent call last):
  File "/Users/tom/.pyenv/versions/3.8.0/bin/gcalcli", line 10, in <module>
    sys.exit(main())
  File "/Users/tom/.pyenv/versions/3.8.0/lib/python3.8/site-packages/gcalcli/cli.py", line 155, in main
    gcal.AgendaQuery(start=parsed_args.start, end=parsed_args.end)
  File "/Users/tom/.pyenv/versions/3.8.0/lib/python3.8/site-packages/gcalcli/gcal.py", line 1197, in AgendaQuery
    return self._display_queried_events(start, end)
  File "/Users/tom/.pyenv/versions/3.8.0/lib/python3.8/site-packages/gcalcli/gcal.py", line 1162, in _display_queried_events
    return self._iterate_events(start, event_list, year_date=year_date)
  File "/Users/tom/.pyenv/versions/3.8.0/lib/python3.8/site-packages/gcalcli/gcal.py", line 1022, in _iterate_events
    if self.options['ignore_declined'] and self._DeclinedEvent(event):
  File "/Users/tom/.pyenv/versions/3.8.0/lib/python3.8/site-packages/gcalcli/gcal.py", line 1123, in _DeclinedEvent
    attendee = [a for a in event['attendees']
IndexError: list index out of range
 ~> gcalcli --version                                                                                               1
gcalcli v4.2.0 (Eric Davis, Brian Hartvigsen, Joshua Crowgey)
~> python --version
Python 3.8.0

The "No-meeting zone" event is just a recurring event from 8:00-13:00 without any attendees or any other attributes.

Any thoughts on how to try to debug it further?

lightheaded commented 2 years ago

Aha, looking at the code when debugging:

        if 'attendees' in event:
            attendee = [a for a in event['attendees']
                        if a['email'] == event['gcalcli_cal']['id']][0]
            if attendee and attendee['responseStatus'] == 'declined':
                return True
        return False

My primary google email is event['gcalcli_cal']['id']][0], but I'm invited via my alias, so the array turns up empty and therefore [0] is out of bounds.

Seeing as the attendee object looks like this

{'email': 'invitee.email@domain.com', 'self': True, 'responseStatus': 'declined'}

probably the 'self' property should be used instead of if a['email'] == event['gcalcli_cal']['id']? I understand this is a corner case, but I assume using an aliases in G-Suite is not that uncommon.