File tree 2 files changed +27
-11
lines changed
zulip/integrations/google
2 files changed +27
-11
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env python3
2
2
import argparse
3
+ import logging
3
4
import os
5
+ import sys
4
6
7
+ from google .auth .exceptions import RefreshError # type: ignore[import-not-found]
5
8
from google .auth .transport .requests import Request # type: ignore[import-not-found]
6
9
from google .oauth2 .credentials import Credentials # type: ignore[import-not-found]
7
10
from google_auth_oauthlib .flow import InstalledAppFlow
@@ -53,7 +56,13 @@ def get_credentials() -> Credentials:
53
56
credentials = Credentials .from_authorized_user_file (credential_path , SCOPES )
54
57
if not credentials or not credentials .valid :
55
58
if credentials and credentials .expired and credentials .refresh_token :
56
- credentials .refresh (Request ())
59
+ try :
60
+ credentials .refresh (Request ())
61
+ except RefreshError :
62
+ logging .error (
63
+ "The credentials have expired. Generate a new client_secret.json file."
64
+ )
65
+ sys .exit (1 )
57
66
else :
58
67
flow = InstalledAppFlow .from_client_secrets_file (
59
68
os .path .join (HOME_DIR , CLIENT_SECRET_FILE ), SCOPES
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import dateutil.parser
15
15
import pytz
16
16
17
17
try :
18
+ from google .auth .exceptions import RefreshError # type: ignore[import-not-found]
18
19
from google .oauth2 .credentials import Credentials # type: ignore[import-not-found]
19
20
from googleapiclient .discovery import build
20
21
except ImportError :
@@ -125,17 +126,23 @@ def get_credentials() -> Credentials:
125
126
def populate_events () -> Optional [None ]:
126
127
creds = get_credentials ()
127
128
service = build ("calendar" , "v3" , credentials = creds )
128
- feed = (
129
- service .events ()
130
- .list (
131
- calendarId = options .calendarID ,
132
- timeMin = datetime .datetime .now (pytz .utc ).isoformat (),
133
- timeMax = datetime .datetime .now (pytz .utc ).isoformat ().split ("T" )[0 ] + "T23:59:59Z" ,
134
- singleEvents = True ,
135
- orderBy = "startTime" ,
129
+ try :
130
+ feed = (
131
+ service .events ()
132
+ .list (
133
+ calendarId = options .calendarID ,
134
+ timeMin = datetime .datetime .now (pytz .utc ).isoformat (),
135
+ timeMax = datetime .datetime .now (pytz .utc ).isoformat ().split ("T" )[0 ] + "T23:59:59Z" ,
136
+ singleEvents = True ,
137
+ orderBy = "startTime" ,
138
+ )
139
+ .execute ()
136
140
)
137
- .execute ()
138
- )
141
+ except RefreshError :
142
+ logging .error (
143
+ "The credentials have expired. Generate a new client_secret.json file and run the get-google-credentials script."
144
+ )
145
+ sys .exit (1 )
139
146
events .clear ()
140
147
for event in feed ["items" ]:
141
148
try :
You can’t perform that action at this time.
0 commit comments