From f194140b79c5d7838e8b3acc603da9d785de38a8 Mon Sep 17 00:00:00 2001 From: Vishnu Vardhan Vithanala <67997162+vishnu-v-vardhan@users.noreply.github.com> Date: Mon, 15 Jan 2024 12:39:25 +0530 Subject: [PATCH 1/4] Update script.py Updated authentication code to a more redundant format. --- Google-Meet-Scheduler/script.py | 56 ++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/Google-Meet-Scheduler/script.py b/Google-Meet-Scheduler/script.py index 8f0c137bf3..33867dbac1 100644 --- a/Google-Meet-Scheduler/script.py +++ b/Google-Meet-Scheduler/script.py @@ -1,26 +1,30 @@ from googleapiclient.discovery import build from uuid import uuid4 from google.auth.transport.requests import Request -from pathlib import Path from google_auth_oauthlib.flow import InstalledAppFlow from typing import Dict, List -from pickle import load, dump +import os +from google.oauth2.credentials import Credentials + +SCOPES = ["https://www.googleapis.com/auth/calendar"] class CreateMeet: - def __init__(self, attendees: Dict[str, str], event_time: Dict[str, str], topic): + def __init__(self, attendees: Dict[str, str], + event_time: Dict[str, str], topic): authe = self._auth() - attendees = [{"email": e} for e in attendees.values()] + attendees_list = [{"email": e} for e in attendees.values()] self.event_states = self._create_event( - attendees, event_time, authe, topic) + attendees_list, event_time, authe, topic) @staticmethod - def _create_event(attendees: List[Dict[str, str]], event_time, authe: build, topic): + def _create_event( + attendees: List[Dict[str, str]], event_time, authe: build, Topic): event = {"conferenceData": {"createRequest": {"requestId": f"{uuid4().hex}", "conferenceSolutionKey": {"type": "hangoutsMeet"}}}, "attendees": attendees, "start": {"dateTime": event_time["start"], 'timeZone': 'Asia/Kolkata'}, "end": {"dateTime": event_time["end"], 'timeZone': 'Asia/Kolkata'}, - "summary": topic, + "summary": Topic, "reminders": {"useDefault": True} } event = authe.events().insert(calendarId="primary", sendNotifications=True, @@ -29,23 +33,24 @@ def _create_event(attendees: List[Dict[str, str]], event_time, authe: build, top @staticmethod def _auth(): - token_file, scopes = Path( - "./token.pickle"), ["https://www.googleapis.com/auth/calendar"] - credentials = None - if token_file.exists(): - with open(token_file, "rb") as token: - credentials = load(token) - if not credentials or not credentials.valid: - if credentials and credentials.expired and credentials.refresh_token: - credentials.refresh(Request()) + creds = None + if os.path.exists("token.json"): + creds = Credentials.from_authorized_user_file("token.json", SCOPES) + # If there are no (valid) credentials available, let the user log in. + 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( - 'credentials.json', scopes) - credentials = flow.run_local_server(port=0) - with open(token_file, "wb") as token: - dump(credentials, token) - calendar_service = build("calendar", "v3", credentials=credentials) - return calendar_service + "credentials.json", SCOPES + ) + creds = flow.run_local_server(port=0) + # Save the credentials for the next run + with open("token.json", "w") as token: + token.write(creds.to_json()) + + service = build("calendar", "v3", credentials=creds) + return service print('------------------------------') @@ -60,9 +65,10 @@ def _auth(): emails = list( input('Enter the emails of guests separated by 1 space each : ').strip().split()) topic = input('Enter the topic of the meeting : ') + time = { - 'start': date+'T'+start+':00.000000', - 'end': date+'T'+end+':00.000000' + 'start': date + 'T' + start + ':00.000000', + 'end': date + 'T' + end + ':00.000000' } guests = {email: email for email in emails} meet = CreateMeet(guests, time, topic) @@ -72,4 +78,4 @@ def _auth(): print('-- Meeting Details --') print('---------------------') for key in keys: - print(key+' : ', details[key]) + print(key + ' : ', details[key]) From 51708ba3f80e4d2075fb6125679965d4a5082a55 Mon Sep 17 00:00:00 2001 From: Vishnu Vardhan Vithanala <67997162+vishnu-v-vardhan@users.noreply.github.com> Date: Mon, 15 Jan 2024 12:51:13 +0530 Subject: [PATCH 2/4] Update script.py Made changes to suppress 'Re-defined variable from outer scope' produced by DeepSource. --- Google-Meet-Scheduler/script.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Google-Meet-Scheduler/script.py b/Google-Meet-Scheduler/script.py index 33867dbac1..5dd42b8cd3 100644 --- a/Google-Meet-Scheduler/script.py +++ b/Google-Meet-Scheduler/script.py @@ -11,20 +11,20 @@ class CreateMeet: def __init__(self, attendees: Dict[str, str], - event_time: Dict[str, str], topic): + event_time: Dict[str, str], Topic): authe = self._auth() attendees_list = [{"email": e} for e in attendees.values()] self.event_states = self._create_event( - attendees_list, event_time, authe, topic) + attendees_list, event_time, authe,Topic) @staticmethod def _create_event( - attendees: List[Dict[str, str]], event_time, authe: build, Topic): + attendees: List[Dict[str, str]], event_time, authe: build, TopiC): event = {"conferenceData": {"createRequest": {"requestId": f"{uuid4().hex}", "conferenceSolutionKey": {"type": "hangoutsMeet"}}}, "attendees": attendees, "start": {"dateTime": event_time["start"], 'timeZone': 'Asia/Kolkata'}, "end": {"dateTime": event_time["end"], 'timeZone': 'Asia/Kolkata'}, - "summary": Topic, + "summary": TopiC, "reminders": {"useDefault": True} } event = authe.events().insert(calendarId="primary", sendNotifications=True, From 5945407b0fd0e4c607d1649af62bd17f9cb5bfb1 Mon Sep 17 00:00:00 2001 From: Vishnu Vardhan Vithanala <67997162+vishnu-v-vardhan@users.noreply.github.com> Date: Mon, 15 Jan 2024 12:58:35 +0530 Subject: [PATCH 3/4] Update script.py Made minor changes to resolve FLK-E231 and PYL-C0412 in DeepSource. --- Google-Meet-Scheduler/script.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Google-Meet-Scheduler/script.py b/Google-Meet-Scheduler/script.py index 5dd42b8cd3..3fb044465b 100644 --- a/Google-Meet-Scheduler/script.py +++ b/Google-Meet-Scheduler/script.py @@ -1,10 +1,11 @@ from googleapiclient.discovery import build -from uuid import uuid4 from google.auth.transport.requests import Request from google_auth_oauthlib.flow import InstalledAppFlow +from google.oauth2.credentials import Credentials + +from uuid import uuid4 from typing import Dict, List import os -from google.oauth2.credentials import Credentials SCOPES = ["https://www.googleapis.com/auth/calendar"] @@ -15,7 +16,7 @@ def __init__(self, attendees: Dict[str, str], authe = self._auth() attendees_list = [{"email": e} for e in attendees.values()] self.event_states = self._create_event( - attendees_list, event_time, authe,Topic) + attendees_list, event_time, authe, Topic) @staticmethod def _create_event( From 532a04d1de32da7387a8fd9d66f41bcbecb2f889 Mon Sep 17 00:00:00 2001 From: Vishnu Vardhan Vithanala <67997162+vishnu-v-vardhan@users.noreply.github.com> Date: Mon, 15 Jan 2024 13:03:54 +0530 Subject: [PATCH 4/4] Update script.py Made minor changes by grouping together a couple of modules to abide to pep8 standard. --- Google-Meet-Scheduler/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Google-Meet-Scheduler/script.py b/Google-Meet-Scheduler/script.py index 3fb044465b..ef29557f0a 100644 --- a/Google-Meet-Scheduler/script.py +++ b/Google-Meet-Scheduler/script.py @@ -1,7 +1,7 @@ from googleapiclient.discovery import build from google.auth.transport.requests import Request -from google_auth_oauthlib.flow import InstalledAppFlow from google.oauth2.credentials import Credentials +from google_auth_oauthlib.flow import InstalledAppFlow from uuid import uuid4 from typing import Dict, List