Adr740's picture
Upload 8 files
411ca77 verified
raw
history blame
1.13 kB
import os
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
from datetime import datetime
def save_logs(path_to_data_to_save, name_to_save, folder_id = "16Vv728HPW2J0BYzgTaBV00nUEc5pRKT-"):
filename = path_to_data_to_save
SERVICE_ACCOUNT_FILE = 'secret_google_service_account.json'
SCOPES = ['https://www.googleapis.com/auth/drive.file']
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
service = build('drive', 'v3', credentials=credentials)
file_metadata = {
'name': name_to_save, # Name of the file to be uploaded
'parents': [folder_id] # Folder ID
}
file_path = filename
# Create a MediaFileUpload object to upload the file
media = MediaFileUpload(file_path)
file = service.files().create(
body=file_metadata,
media_body=media,
fields='id'
).execute()
# Print the file ID of the uploaded file
print('Saved in Google Drive - File ID: %s' % file.get('id'))
return file