|
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(filename, folder_id = ""): |
|
|
|
|
|
now = datetime.now() |
|
|
|
|
|
|
|
|
|
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': filename, |
|
'parents': [folder_id] |
|
} |
|
|
|
|
|
file_path = filename |
|
|
|
|
|
media = MediaFileUpload(file_path) |
|
|
|
|
|
file = service.files().create( |
|
body=file_metadata, |
|
media_body=media, |
|
fields='id' |
|
).execute() |
|
|
|
|
|
print('Saved in Google Drive - File ID: %s' % file.get('id')) |