Spaces:
Sleeping
Sleeping
import os | |
import gspread | |
import base64 | |
from dotenv import load_dotenv | |
from oauth2client.service_account import ServiceAccountCredentials | |
from google.oauth2 import service_account | |
load_dotenv() | |
#Source: https://stackoverflow.com/questions/71544103/how-can-we-store-a-json-credential-to-env-variable-in-python | |
def create_keyfile_dict(): | |
variables_keys = { | |
"type": os.getenv("TYPE"), | |
"project_id": os.getenv("PROJECT_ID"), | |
"private_key_id": os.getenv("PRIVATE_KEY_ID"), | |
"private_key": (os.environ['PRIVATE_KEY']).replace('\\n', '\n'), | |
"client_email": os.getenv("CLIENT_EMAIL"), | |
"client_id": os.getenv("CLIENT_ID"), | |
"auth_uri": os.getenv("AUTH_URI"), | |
"token_uri": os.getenv("TOKEN_URI"), | |
"auth_provider_x509_cert_url": os.getenv("AUTH_PROVIDER_X509_CERT_URL"), | |
"client_x509_cert_url": os.getenv("CLIENT_X509_CERT_URL") | |
} | |
return variables_keys | |
def define_scope(): | |
scope = ['https://spreadsheets.google.com/feeds', | |
'https://www.googleapis.com/auth/drive'] | |
return scope | |
def credentials(): | |
creds = ServiceAccountCredentials.from_json_keyfile_name(create_keyfile_dict()) | |
return creds | |