I want to access multiple google calendars from python: there is a primary calendar connected to a google account, also other (secondary) calendars can be created. Access to the secondary calendars is possible after google authorization to the primary one. I want to make changes to the secondary calendars without repeating authorization procedure every time, i.e. login once and store auth information in the class attribute. For example:
class Gcal:
auth = None
@classmethod
def authorize(cls, account):
cls.auth = auth_function()
def __init__(self, calendar_name, account='user@gmail.com'):
if not self.auth:
self.authorize(account)
self.calendar = self.get_cal(calendar_name)
def get_cal(self, calendar_name):
pass
if __name__ == '__main__':
g1 = Gcal('1')
g2 = Gcal('2')
g3 = Gcal('3')
print(g1, g2, g3)
The code above works without additional calls of auth_function()
, but I'd like to know if this is a good practice of object oriented use of python? Are there side effects?