]> git.cworth.org Git - turbot/blobdiff - turbot/sheets.py
Put a message into the channel when a user edits a puzzle
[turbot] / turbot / sheets.py
index 43b4f2931bf4b62b8308fa849eefc29fed305a57..bc7c7c68ceb777a2e0cd86b366264ae1e47da3ae 100644 (file)
@@ -61,7 +61,10 @@ def sheets_create_for_puzzle(turb, puzzle):
         insertDataOption='INSERT_ROWS',
         body={
             'range': 'A1:A2',
-            'values': [['=HYPERLINK("'+url_link+'","'+url_text+'")'], ['=HYPERLINK("'+channel_url_link+'","'+channel_url_text+'")']]
+            'values': [
+                ['=HYPERLINK("'+url_link+'","'+url_text+'")'],
+                ['=HYPERLINK("'+channel_url_link+'","'+channel_url_text+'")']
+            ]
         }).execute()
 
     # Copy some sheets from the Template spreadsheet
@@ -81,17 +84,27 @@ def sheets_create_for_puzzle(turb, puzzle):
 
 def renameSheet(turb, url, newName):
     id = extractIdFromSheetUrl(url)
-    turb.sheets.batchUpdate(body={
-                                "updateSheetProperties": {
-                                    "properties": {
-                                        "sheetId": id,
-                                        "title": newName
-                                    }
-                                }}).execute()
+    requests = []
+    requests.append({
+        'updateSpreadsheetProperties': {
+            'properties': {
+                'title': newName
+            },
+            'fields': 'title'
+        }
+    })
+
+    body = {
+        'requests': requests
+    }
+
+    turb.sheets.batchUpdate(spreadsheetId = id,
+                            body=body
+                            ).execute()
 
 def extractIdFromSheetUrl(url):
-    # Google sheet ids are between the /d/ and /edit in the url, like https://docs.google.com/spreadsheets/d/1dxHBzjenjhCAJQ8lM0skJO2mxlup8aWZm0-LaXeVPrg/edit#gid=0
+    # Google sheet ids are between the /d/ and /edit in the url, like
+    # https://docs.google.com/spreadsheets/d/1dxHBzjen...-LaXeVPrg/edit#gid=0
     startIndex = url.find('/d/') + 3
     endIndex = url.find('/edit')
     return url[startIndex : endIndex]
-    
\ No newline at end of file