#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from constants import (GOOGLE_SHEETS_HOME, GOOGLE_DRIVE_AUTH)
class GSheetUtil:

    def __init__(self):
        #connect and open the google sheet
        scope = [GOOGLE_SHEETS_HOME, GOOGLE_DRIVE_AUTH]
        #credentials json file generated by googleAPI
        self.creds = ServiceAccountCredentials.from_json_keyfile_name('config/client_secret.json', scope)
        self.client = gspread.authorize(self.creds)
        #open google sheet
        self.sheet = self.client.open('Plan of Investment')
        print('######## google sheet opened ########')

    def getSheet(self):
        return self.sheet

    def renewAccessToken(self):
        if self.creds.access_token_expired:
            print('access_token_expired')
            self.client.login()
