1 PUZZLE_TEMPLATE_ID = "1drSoyrE4gM3JaGweDkOybwXWdKPIDTfUmB1gQCYS3Uw"
2 PUZZLE_TEMPLATE_SHEETS = ["Text", "Grid"]
4 def sheets_create(turb, name):
5 """Create a new sheet with the given name.
7 Returns the dict with 'id' and 'url'of the spreadsheet.
10 # Create a new spreadsheet
17 new_sheet = turb.sheets.create(body=spreadsheet_body).execute()
19 # Now that we've created a new sheet, we need to also allow anyone
20 # with the link to the sheet to be able to edit it.
21 turb.permissions.create(fileId=new_sheet["spreadsheetId"],
22 body={'type': 'anyone', 'role': 'writer'},
23 fields='id').execute()
26 'id': new_sheet["spreadsheetId"],
27 'url': new_sheet["spreadsheetUrl"]
30 def sheets_create_for_puzzle(turb, puzzle):
31 """Creates a new sheet for a puzzle of the given name
33 Like sheets_create(), but also copies the puzzle template sheet.
35 Here, 'puzzle' is a dict that must have a 'name' key and may optionally
36 have a 'channel_url' or 'url' key."""
38 # First create the new sheet
39 new_sheet = sheets_create(turb, puzzle['name'])
41 # Insert some useful links into the sheet
43 url_text = "Original puzzle is at: {}".format(puzzle['url'])
47 if 'channel_url' in puzzle:
48 channel_url_text = "Discussion for this puzzle is at: {}".format(
49 puzzle['channel_url'])
53 turb.sheets.values().append(
54 spreadsheetId=new_sheet['id'],
56 valueInputOption='USER_ENTERED',
57 insertDataOption='INSERT_ROWS',
60 'values': [['=HYPERLINK('+url_text+')'], ['=HYPERLINK('+channel_url_text+')']]
63 # Copy some sheets from the Template spreadsheet
65 response = turb.sheets.get(spreadsheetId=PUZZLE_TEMPLATE_ID).execute()
67 for sheet in response["sheets"]:
68 if sheet["properties"]["title"] in PUZZLE_TEMPLATE_SHEETS:
69 turb.sheets.sheets().copyTo(spreadsheetId=PUZZLE_TEMPLATE_ID,
70 sheetId=sheet["properties"]["sheetId"],
72 "destinationSpreadsheetId":