new_sheet = sheets_create(turb, puzzle['name'])
# Insert some useful links into the sheet
+ url_link=''
if 'url' in puzzle:
url_text = "Original puzzle is at: {}".format(puzzle['url'])
+ url_link = puzzle['url']
else:
url_text = ''
+ channel_url_link = ''
if 'channel_url' in puzzle:
channel_url_text = "Discussion for this puzzle is at: {}".format(
puzzle['channel_url'])
+ channel_url_link = puzzle['channel_url']
else:
channel_url_text = ''
insertDataOption='INSERT_ROWS',
body={
'range': 'A1:A2',
- 'values': [[url_text], [channel_url_text]]
+ 'values': [['=HYPERLINK("'+url_link+'","'+url_text+'")'], ['=HYPERLINK("'+channel_url_link+'","'+channel_url_text+'")']]
}).execute()
# Copy some sheets from the Template spreadsheet
}).execute()
return new_sheet
+
+def renameSheet(turb, url, newName):
+ id = extractIdFromSheetUrl(url)
+ 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
+ startIndex = url.find('/d/') + 3
+ endIndex = url.find('/edit')
+ return url[startIndex : endIndex]
+
\ No newline at end of file