Search code examples
pythongoogle-apigoogle-calendar-apigcsa

gcsa - Pythonic wrapper for Google Calendar API


this is my first post and I am very new to python, so excuse me in advance if my questions/etiquette are not polished enough. This might be a very trivial question.

Here is the thing: I am trying to develop an app that will periodically check a calendar via the Google Calendar API for new events, then produce a QR code including the calendar ID and event ID.

Since I am new to python, i searched for something that would maybe make things smoother and found gcsa: https://github.com/kuzmoyev/google-calendar-simple-api ,which is very nice and convenient.

The issue I am having is that using the gcsa, the default way of listing events in a calendar returns only the event timing and name:

from gcsa.google_calendar import GoogleCalendar

calendar = GoogleCalendar('primary')
for event in calendar:
    print(event)

gives me 2021-02-16 10:30:00-03:00 - TEST

And as the newbie I am, I cannot for the life of me find a way for it to return other data from the events resource, such as 'id' (which i need) and 'status' (which i will use as a flag for new/old events).

From what I understand, it will be necessary to tweak the code just a little bit, maybe in the google_calendar.py, maybe in the event_serialyzer.py. Probably some very minor dumb stuff i should have already noticed.

I cant even pinpoint exactly where is the GoogleCalendar() being executed and where does it get the displayed data from, but my guess is maybe line 321 or 376 in google_calendar.py? Beats me.

Its been two days fussing around this issue and no luck, would anybody please have any insight on this?

I know there are ways to request the event object directly in python, as demonstrated in https://developers.google.com/calendar/v3/reference/events/list#python , and that will be my next option.

If it turns out it is too awkward or not worth the hassle, I'll just go without gcsa and make the request the usual way.

Thank you all very much!


Solution

  • Your assumption that gcsa only returns the event's time and the name is wrong. Inspecting a custom object using print is not very productive. All you are going to see is the string representation of the object (as dictated by its __str__ method).

    You should inspect objects either by using an actual debugger, or by at least printing the available attributes using vars(obj) or dir(obj), or of course by looking at the actual class.

    In this case, if you look at the actual class, you will see that it contains a lot more than only the start date and the name. It also has (among other attributes) event_id.