Skip to content

Add quarterly business review demo#16

Merged
grant merged 10 commits intogoogleworkspace:masterfrom
mcodik:master
Aug 3, 2018
Merged

Add quarterly business review demo#16
grant merged 10 commits intogoogleworkspace:masterfrom
mcodik:master

Conversation

@mcodik
Copy link
Copy Markdown
Contributor

@mcodik mcodik commented Jul 18, 2018

No description provided.

## Getting started

* Follow the [Sheets API python quickstart](https://developers.google.com/sheets/api/quickstart/python)
* Make sure to save the `client-secrets.json` file in your working directory
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently renamed this file to credentials.json. Either update your README and code or mention that they should rename it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!


// Add data from the stub customer service
$ python qbr_tool.py add_customers \
--spreadsheet_id <your spreadsheet id> \
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the spreadsheet ID printed out as a result of the previous command? If so, mention that in the comments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

developer project
* Run the tool with no arguments to complete the OAuth consent flow:

<pre>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: More common to use tripple backticks instead of pre tags.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

* Run the tool with no arguments to complete the OAuth consent flow:

<pre>
$ python qbr_tool.py
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Remove unnecessary leading whitespace, here and below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

* Run the tool:

<pre>
// Create the spreadsheet from the Google Slides template.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a hash sign for comments, instead of double slash, to conform with bash syntax.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

def ExecuteRead(self):
filters = list(self._data_filters.values())
get_body = {'dataFilters': filters}
read_fields = ('sheets.properties.sheetId,sheets.data.rowData.' +
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: Would it be more readable to define these as a list an then join them?

read_fields = ','.join([
    'sheets.properties.sheetId',
    'sheets.data.rowData.values.formattedValue',
    'developerMetadata.metadataValue'
])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

def GetColumnData(self, column_id):
index = list(self._data_filters.keys()).index(column_id)
data = self._spreadsheet.get('sheets')[0].get('data')[index]
values = []
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: More compact, but perhaps less readable, to use a list comprehension:

values = [row.get('values')[0].get('formattedValue') for row in data.get('rowData')]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

self._requests.append(request)

def ExecuteBatchUpdate(self):
body = {'requests': self._requests}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some number of requests where it would make sense to break them into multiple HTTP requests? AKA, how many placeholders could you have before this fails?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I havent tested it in a while, but the intent is for this to be OK for ~thousands of placeholders.

@erickoledadevrel erickoledadevrel self-assigned this Jul 24, 2018
@mcodik
Copy link
Copy Markdown
Contributor Author

mcodik commented Jul 30, 2018

added a commit that addresses the feedback, thanks for taking a look!

# Create the spreadsheet from the Google Slides template.
# For example, 13My9SxkotWssCc2F5yaXp2fzGrzoYV6maytr3qAT9GQ
$ python qbr_tool.py create_sheet --template_id <your template id>;
Spreadsheet URL: https://docs.google.com/spreadsheets/d/<spreadsheet id>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Put the output in a comment, to indicate they shouldn't paste it into the command line.

store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update this to credentials.json as well.

@grant
Copy link
Copy Markdown
Contributor

grant commented Jul 30, 2018

Note: I've fixed the Travis builds since the creation of this PR.
Please be sure the build passes before merging.

@mcodik
Copy link
Copy Markdown
Contributor Author

mcodik commented Jul 30, 2018

Travis is now green, ptal!

@grant grant merged commit 6b513c2 into googleworkspace:master Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants