Google Drive
Last updated
https://drive.google.com/drive/folders/1r1cDZzgE7wclTYMv_Xzdv98znO9kHN8_
→ Folder ID: 1r1cDZzgE7wclTYMv_Xzdv98znO9kHN8_{
"packages": [
"google-api-python-client",
"google-auth"
]
}import polars as pl
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.http import MediaIoBaseDownload
import io, os
# Google Drive folder ID
FOLDER_ID = "<REPLACE_WITH_FOLDER_ID>"
# Path to your service account credentials
SERVICE_ACCOUNT_FILE = "./mcp.json"
# Drive API scope
SCOPES = ["https://www.googleapis.com/auth/drive.readonly"]
def transform():
# Authenticate using the service account
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES
)
service = build("drive", "v3", credentials=creds)
# Query all Excel files in the folder
query = f"'{FOLDER_ID}' in parents and (name contains '.xlsx' or name contains '.xls')"
results = service.files().list(q=query, fields="files(id, name)").execute()
files = results.get("files", [])
# Download files into the artifacts folder
for f in files:
print(f"Downloading {f['name']}...")
request = service.files().get_media(fileId=f["id"])
with io.FileIO(os.path.join(os.environ["ARTIFACT_FOLDER"], f["name"]), "wb") as fh:
downloader = MediaIoBaseDownload(fh, request)
done = False
while not done:
status, done = downloader.next_chunk()
if status:
print(f" {int(status.progress() * 100)}%")
print("✅ All files downloaded successfully")
# Return an empty DataFrame (optional)
df = pl.DataFrame()
return df