-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgoogle_drive_upload.py
More file actions
28 lines (21 loc) · 844 Bytes
/
google_drive_upload.py
File metadata and controls
28 lines (21 loc) · 844 Bytes
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
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
def save_notes_to_drive(notes_text, filename="Generated_Notes.txt", folder_id=None):
creds = service_account.Credentials.from_service_account_file('client_secrets.json')
service = build('drive', 'v3', credentials=creds)
with open(filename, 'w') as f:
f.write(notes_text)
file_metadata = {
'name': filename,
'mimeType': 'text/plain'
}
if folder_id:
file_metadata['parents'] = [folder_id]
media = MediaFileUpload(filename, mimetype='text/plain')
file = service.files().create(
body=file_metadata,
media_body=media,
fields='id'
).execute()
print(f"File uploaded to Google Drive with ID: {file.get('id')}")