-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdrive.py
40 lines (33 loc) · 934 Bytes
/
gdrive.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
from pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive
from pprint import pprint
from datetime import datetime
def get_authentication():
settings = {
"client_config_backend": "service",
"service_config": {
"client_json_file_path": "service-secrets.json",
},
}
gauth = GoogleAuth(settings=settings)
gauth.ServiceAuth()
return gauth
auth = get_authentication()
drive = GoogleDrive(auth)
def create_note(content):
files = drive.ListFile().GetList()
inbox_folder = None
for file in files:
if "Inbox" in file["title"]:
inbox_folder = file["id"]
break
now = datetime.now().strftime("%d-%m-%Y-%H-%M-%S")
note = drive.CreateFile(
{
"title": f"{now}.md",
"parents": [{"id": inbox_folder}],
}
)
note.SetContentString(content)
note.Upload()
return note