Created
July 16, 2019 07:05
-
-
Save DataSolveProblems/28ac9c33620e4376759d8077f9babf1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Google import Create_Service | |
CLIENT_SECRET_FILE = '<client secret.json>' | |
API_SERVICE_NAME = 'sheets' | |
API_VERSION = 'v4' | |
SCOPES = ['https://www.googleapis.com/auth/spreadsheets'] | |
service = Create_Service(CLIENT_SECRET_FILE, API_SERVICE_NAME, API_VERSION, SCOPES) | |
gsheet_id = '<google sheet id>' | |
spreadsheets = service.spreadsheets() | |
def add_sheets(gsheet_id, sheet_name): | |
try: | |
request_body = { | |
'requests': [{ | |
'addSheet': { | |
'properties': { | |
'title': sheet_name, | |
'tabColor': { | |
'red': 0.44, | |
'green': 0.99, | |
'blue': 0.50 | |
} | |
} | |
} | |
}] | |
} | |
response = spreadsheets.batchUpdate( | |
spreadsheetId=gsheet_id, | |
body=request_body | |
).execute() | |
return response | |
except Exception as e: | |
print(e) | |
xSheets = ['North', 'South', 'East', 'West'] | |
for name in xSheets: | |
print(add_sheets(gsheet_id, name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment