]> git.cworth.org Git - turbot/commitdiff
Switch from using append() to update() for inserting into a spreadsheet
authorCarl Worth <cworth@cworth.org>
Wed, 13 Jan 2021 04:03:36 +0000 (20:03 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 13 Jan 2021 04:03:36 +0000 (20:03 -0800)
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).

turbot/sheets.py

index 56adef6cf8a7433ef6614b99b1fb285ba06e15af..c042b4daf28e1358ac161142c16bf6b3472bc196 100644 (file)
@@ -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': [