Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 33 additions & 26 deletions Google-Meet-Scheduler/script.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
from googleapiclient.discovery import build
from uuid import uuid4
from google.auth.transport.requests import Request
from pathlib import Path
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow

from uuid import uuid4
from typing import Dict, List
from pickle import load, dump
import os

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,
Expand All @@ -29,23 +34,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('------------------------------')
Expand All @@ -60,9 +66,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)
Expand All @@ -72,4 +79,4 @@ def _auth():
print('-- Meeting Details --')
print('---------------------')
for key in keys:
print(key+' : ', details[key])
print(key + ' : ', details[key])