From: Carl Worth Date: Wed, 13 Jan 2021 04:03:36 +0000 (-0800) Subject: Switch from using append() to update() for inserting into a spreadsheet X-Git-Url: https://git.cworth.org/git?p=turbot;a=commitdiff_plain;h=375bba612d7f18369301f2e75529c07a9cc81bf8 Switch from using append() to update() for inserting into a spreadsheet The append() method was the entirely wrong thing: It puts data in as new rows below existing data. The update() method does what we want, (sets data at a specific range). --- diff --git a/turbot/sheets.py b/turbot/sheets.py index 56adef6..c042b4d 100644 --- a/turbot/sheets.py +++ b/turbot/sheets.py @@ -92,14 +92,14 @@ def sheets_create_for_puzzle(turb, puzzle, folder_id): if 'url' in puzzle: url_link = puzzle['url'] url_text = "Original puzzle link" - spreadsheet_insert_data( + spreadsheet_update_data( turb, spreadsheet_id, "B1:B1", '=HYPERLINK("{}","{}")'.format(url_link, url_text)) if 'channel_url' in puzzle: url_link = puzzle['channel_url'] url_text = "Slack channel link" - spreadsheet_insert_data( + spreadsheet_update_data( turb, spreadsheet_id, "B2:B2", '=HYPERLINK("{}","{}")'.format(url_link, url_text)) @@ -108,13 +108,12 @@ def sheets_create_for_puzzle(turb, puzzle, folder_id): 'url': spreadsheet_url } -def spreadsheet_insert_data(turb, spreadsheet_id, range, text): +def spreadsheet_update_data(turb, spreadsheet_id, range, text): - turb.sheets.values().append( + turb.sheets.values().update( spreadsheetId=spreadsheet_id, range=range, valueInputOption='USER_ENTERED', - insertDataOption='INSERT_ROWS', body={ 'range': range, 'values': [