X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=turbot%2Fsheets.py;h=9f8b7c3e0d38eabb0fd08332b684ea39789fea66;hb=3f380c6d5227b99d703d5c8ed3c753e4d179415a;hp=047f793b0c22c805615b215a5f803d81dec56e65;hpb=dc43fb79c5f826d9f85a8078663c4047d7cb0622;p=turbot diff --git a/turbot/sheets.py b/turbot/sheets.py index 047f793..9f8b7c3 100644 --- a/turbot/sheets.py +++ b/turbot/sheets.py @@ -1,5 +1,6 @@ PUZZLE_TEMPLATE_ID = "1drSoyrE4gM3JaGweDkOybwXWdKPIDTfUmB1gQCYS3Uw" -PUZZLE_TEMPLATE_SHEETS = ["Text", "Grid"] +PUZZLE_TEMPLATE_SHEETS = ["Text", "Square grid", "Hex Grid", + "Formula reference: indexing"] def sheets_create(turb, name): """Create a new sheet with the given name. @@ -61,7 +62,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 @@ -78,3 +82,30 @@ def sheets_create_for_puzzle(turb, puzzle): }).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/1dxHBzjen...-LaXeVPrg/edit#gid=0 + startIndex = url.find('/d/') + 3 + endIndex = url.find('/edit') + return url[startIndex : endIndex]