Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e7b2366

Browse files
Merge pull request avinashkranjan#3094 from vishnu-v-vardhan/main
Update script.py
2 parents 92a3d26 + 532a04d commit e7b2366

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

‎Google-Meet-Scheduler/script.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
from googleapiclient.discovery import build
2-
from uuid import uuid4
32
from google.auth.transport.requests import Request
4-
from pathlib import Path
3+
from google.oauth2.credentials import Credentials
54
from google_auth_oauthlib.flow import InstalledAppFlow
5+
6+
from uuid import uuid4
67
from typing import Dict, List
7-
from pickle import load, dump
8+
import os
9+
10+
SCOPES = ["https://www.googleapis.com/auth/calendar"]
811

912

1013
class CreateMeet:
11-
def __init__(self, attendees: Dict[str, str], event_time: Dict[str, str], topic):
14+
def __init__(self, attendees: Dict[str, str],
15+
event_time: Dict[str, str], Topic):
1216
authe = self._auth()
13-
attendees = [{"email": e} for e in attendees.values()]
17+
attendees_list = [{"email": e} for e in attendees.values()]
1418
self.event_states = self._create_event(
15-
attendees, event_time, authe, topic)
19+
attendees_list, event_time, authe, Topic)
1620

1721
@staticmethod
18-
def _create_event(attendees: List[Dict[str, str]], event_time, authe: build, topic):
22+
def _create_event(
23+
attendees: List[Dict[str, str]], event_time, authe: build, TopiC):
1924
event = {"conferenceData": {"createRequest": {"requestId": f"{uuid4().hex}", "conferenceSolutionKey": {"type": "hangoutsMeet"}}},
2025
"attendees": attendees,
2126
"start": {"dateTime": event_time["start"], 'timeZone': 'Asia/Kolkata'},
2227
"end": {"dateTime": event_time["end"], 'timeZone': 'Asia/Kolkata'},
23-
"summary": topic,
28+
"summary": TopiC,
2429
"reminders": {"useDefault": True}
2530
}
2631
event = authe.events().insert(calendarId="primary", sendNotifications=True,
@@ -29,23 +34,24 @@ def _create_event(attendees: List[Dict[str, str]], event_time, authe: build, top
2934

3035
@staticmethod
3136
def _auth():
32-
token_file, scopes = Path(
33-
"./token.pickle"), ["https://www.googleapis.com/auth/calendar"]
34-
credentials = None
35-
if token_file.exists():
36-
with open(token_file, "rb") as token:
37-
credentials = load(token)
38-
if not credentials or not credentials.valid:
39-
if credentials and credentials.expired and credentials.refresh_token:
40-
credentials.refresh(Request())
37+
creds = None
38+
if os.path.exists("token.json"):
39+
creds = Credentials.from_authorized_user_file("token.json", SCOPES)
40+
# If there are no (valid) credentials available, let the user log in.
41+
if not creds or not creds.valid:
42+
if creds and creds.expired and creds.refresh_token:
43+
creds.refresh(Request())
4144
else:
4245
flow = InstalledAppFlow.from_client_secrets_file(
43-
'credentials.json', scopes)
44-
credentials = flow.run_local_server(port=0)
45-
with open(token_file, "wb") as token:
46-
dump(credentials, token)
47-
calendar_service = build("calendar", "v3", credentials=credentials)
48-
return calendar_service
46+
"credentials.json", SCOPES
47+
)
48+
creds = flow.run_local_server(port=0)
49+
# Save the credentials for the next run
50+
with open("token.json", "w") as token:
51+
token.write(creds.to_json())
52+
53+
service = build("calendar", "v3", credentials=creds)
54+
return service
4955

5056

5157
print('------------------------------')
@@ -60,9 +66,10 @@ def _auth():
6066
emails = list(
6167
input('Enter the emails of guests separated by 1 space each : ').strip().split())
6268
topic = input('Enter the topic of the meeting : ')
69+
6370
time = {
64-
'start': date+'T'+start+':00.000000',
65-
'end': date+'T'+end+':00.000000'
71+
'start': date+'T'+start+':00.000000',
72+
'end': date+'T'+end+':00.000000'
6673
}
6774
guests = {email: email for email in emails}
6875
meet = CreateMeet(guests, time, topic)
@@ -72,4 +79,4 @@ def _auth():
7279
print('-- Meeting Details --')
7380
print('---------------------')
7481
for key in keys:
75-
print(key+' : ', details[key])
82+
print(key+' : ', details[key])

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /