-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfolderInDrive.py
49 lines (42 loc) · 1.35 KB
/
folderInDrive.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
import requests
import os
import csv
import json
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
def writeInCSV(fileName,string_to_write):
firstSplit = string_to_write.split('\n')
with open(fileName,'w') as file:
for line in firstSplit:
file.write(line)
file.write('\n')
gauth = GoogleAuth()
# Try to load saved client credentials
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
# Authenticate if they're not there
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh them if expired
gauth.Refresh()
else:
# Initialize the saved creds
gauth.Authorize()
# Save the current credentials to a file
gauth.SaveCredentialsFile("mycreds.txt")
drive = GoogleDrive(gauth)
'''
fileOutsidePune = drive.CreateFile({"parents": [{"kind": "drive#fileLink","id": "1kxRZk7hBjBDtUgKm4hYgHvw2NDZw2V8R"}]})
fileOutsidePune.SetContentFile("outsidePune.csv")
fileOutsidePune.Upload()
'''
folder_metadata = {
'title': 'shellkore_folder',
# Define the file type as folder
'mimeType': 'application/vnd.google-apps.folder',
# ID of the parent folder
'parents': [{"kind": "drive#fileLink", "id": "1jjWjQkEbKTmj2T6CR2utL7P1VBja-M5A"}]
}
folder = drive.CreateFile(folder_metadata)
folder.Upload()