Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def sheet_copy(file_id, dist_id, title=None, copy_permissions=False):
"""
REF: https://github.com/burnash/gspread
I reuse the gspread function to make this request.
"""
self = G_ACCESS
url = "{0}/{1}/copy".format(DRIVE_FILES_API_V2_URL, file_id)
payload = {
"title": title,
"mimeType": "application/vnd.google-apps.spreadsheet",
"parents": [{"kind": "drive#childList", "id": dist_id}],
}
r = self.request("post", url, json=payload)
spreadsheet_id = r.json()["id"]
new_spreadsheet = self.open_by_key(spreadsheet_id)
if copy_permissions:
original = self.open_by_key(file_id)
permissions = original.list_permissions()
for p in permissions:
def create_sheet_container(file_id, dir_name):
"""
REF: https://github.com/burnash/gspread
I reuse the gspread function to make this API request.
"""
self = G_ACCESS
payload = {
"title": dir_name,
"mimeType": "application/vnd.google-apps.folder",
"parents": [{"kind": "drive#childList", "id": file_id}],
}
r = self.request("post", DRIVE_FILES_API_V2_URL, json=payload)
return r.json()["id"]
scope = [
'https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive'
]
Otherwise you will get an ``Insufficient Permission`` error
when you try to create a new spreadsheet.
"""
payload = {
'title': title,
'mimeType': 'application/vnd.google-apps.spreadsheet'
}
r = self.request(
'post',
DRIVE_FILES_API_V2_URL,
json=payload
)
spreadsheet_id = r.json()['id']
return self.open_by_key(spreadsheet_id)
def list_permissions(self, file_id):
"""Retrieve a list of permissions for a file.
:param file_id: a spreadsheet ID (aka file ID.)
:type file_id: str
"""
url = '{0}/{1}/permissions'.format(DRIVE_FILES_API_V2_URL, file_id)
r = self.request('get', url)
return r.json()['items']
scope = [
'https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive'
]
Otherwise you will get an ``Insufficient Permission`` error
when you try to create a new spreadsheet.
"""
payload = {
'title': title,
'mimeType': 'application/vnd.google-apps.spreadsheet'
}
r = self.request(
'post',
DRIVE_FILES_API_V2_URL,
json=payload
)
spreadsheet_id = r.json()['id']
return self.open_by_key(spreadsheet_id)
def del_spreadsheet(self, file_id):
"""Deletes a spreadsheet.
:param file_id: a spreadsheet ID (aka file ID.)
"""
url = '{0}/{1}'.format(
DRIVE_FILES_API_V2_URL,
file_id
)
self.request('delete', url)