-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.py
38 lines (33 loc) · 1.01 KB
/
auth.py
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
38
# auth.py
import os
from dotenv import load_dotenv
from google.oauth2 import service_account
import gspread
load_dotenv()
SCOPES = os.getenv("SCOPES").split(",")
SERVICE_ACCOUNT_FILE = os.getenv("SERVICE_ACCOUNT_FILE")
def get_credentials():
try:
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE,
scopes=SCOPES
)
return credentials
except Exception as e:
print(f"Error loading credentials: {e}")
raise
def get_ga_client(credentials):
from google.analytics.data_v1beta import BetaAnalyticsDataClient
try:
ga_client = BetaAnalyticsDataClient(credentials=credentials)
return ga_client
except Exception as e:
print(f"Error initializing GA client: {e}")
raise
def get_sheet_client(credentials):
try:
sheet_client = gspread.authorize(credentials)
return sheet_client
except Exception as e:
print(f"Error initializing Sheets client: {e}")
raise