| import os, pickle | |
| from google_auth_oauthlib.flow import InstalledAppFlow | |
| from google.auth.transport.requests import Request | |
| SCOPES = [ | |
| 'https://www.googleapis.com/auth/calendar', | |
| 'https://www.googleapis.com/auth/gmail.readonly', | |
| 'https://www.googleapis.com/auth/gmail.send' | |
| ] | |
| def authenticate_google_services(): | |
| os.system(f"gdown https://drive.google.com/uc?id=1EVsYlH4LRx4fDcllwfyijJYv6rexUTzR -O client_secret.json") | |
| creds = None | |
| if os.path.exists('token.pkl'): | |
| with open('token.pkl', 'rb') as token: | |
| creds = pickle.load(token) | |
| if not creds or not creds.valid: | |
| if creds and creds.expired and creds.refresh_token: | |
| creds.refresh(Request()) | |
| else: | |
| flow = InstalledAppFlow.from_client_secrets_file('client_secret.json', SCOPES) | |
| creds = flow.run_console() | |
| with open('token.pkl', 'wb') as token: | |
| pickle.dump(creds, token) | |
| return creds | |