-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
37 lines (26 loc) · 1.1 KB
/
utils.py
File metadata and controls
37 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from pprint import pprint
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow
SCOPES = ["https://www.googleapis.com/auth/spreadsheets"]
SPREADSHEET_ID = "1DwihAqU_0W-z4bn5LQRb3IKuw9DMaXEH-RQG-J2QeXg"
SOURCE_SHEET_NAME = "Language requests"
def load_and_refresh_credentials(filename="token.json", scopes=None):
creds = None
if os.path.exists(filename):
creds = Credentials.from_authorized_user_file(filename, scopes=scopes)
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
# Save the refreshed token
with open(filename, "w") as token:
token.write(creds.to_json())
return creds
def update_token():
flow = InstalledAppFlow.from_client_secrets_file(
'client_secret.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.json', 'w') as token_file:
token_file.write(creds.to_json())
print("✅ token.json created successfully!")