-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgplus.py
54 lines (40 loc) · 1.35 KB
/
gplus.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
50
51
52
53
54
from gspread import Client
class ClientPlus( Client ):
"""
Create a new class which adds the get_all_files function
to the Client
"""
def get_all_files(self):
files = []
page_token = ''
url = "https://www.googleapis.com/drive/v3/files"
params = {
'corpora':['user', 'domain'],
"pageSize": 1000,
'supportsTeamDrives': True,
'includeTeamDriveItems': True,
}
while page_token is not None:
if page_token:
params['pageToken'] = page_token
res = self.request('get', url, params=params).json()
files.extend(res['files'])
page_token = res.get('nextPageToken', None)
return files
def get_file_id( self, file_name ):
url = "https://www.googleapis.com/drive/v3/files"
params = {
'q': "name ='{}'".format(file_name),
'corpora':['user', 'domain'],
"pageSize": 1000,
'supportsTeamDrives': True,
'includeTeamDriveItems': True,
}
res = self.request('get', url, params=params).json()
try:
for fyl in res['files']:
if 'id' in fyl:
return fyl['id']
except:
pass
return None