Skip to content

Instantly share code, notes, and snippets.

@flying-falcon
Created July 24, 2020 13:54
Show Gist options
  • Save flying-falcon/dddc564877f77d1e3a85e3ceb07ab314 to your computer and use it in GitHub Desktop.
Save flying-falcon/dddc564877f77d1e3a85e3ceb07ab314 to your computer and use it in GitHub Desktop.
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
class Report():
def __init__(self, documentId):
self.scopes = {
'docs': ['https://www.googleapis.com/auth/documents', 'https://www.googleapis.com/auth/documents.readonly']
}
self.documentId = documentId
self.credentials = {
'docs': ServiceAccountCredentials.from_json_keyfile_name('./auth.json', scopes=self.scopes['docs'])
}
# https://developers.google.com/drive/api/v3/quickstart/python
self.service = {
'docs': build('docs', 'v1', credentials=self.credentials['docs'])
}
self.doc_body = [
{
"insertText": {
"text": "Data\n\tSample data in last 24 hrs:\n\t\tExample text \n\t\tExample Text\n\t\tExample Text\n\tSample Data 2 in last 24 hrs\n",
"location": {
"index": 1
}
}
},
{
"updateTextStyle": {
"range": {
"startIndex": 1,
"endIndex": 34
},
"textStyle": {
"bold": True
},
"fields": "bold"
}
},
{
"updateTextStyle": {
"range": {
"startIndex": 81,
"endIndex": 110
},
"textStyle": {
"bold": True
},
"fields": "bold"
}
},
{
"createParagraphBullets": {
"range": {
"startIndex": 1,
"endIndex": 110
},
"bulletPreset": "BULLET_DISC_CIRCLE_SQUARE"
}
},
{
"insertText": {
"text": "\nAgenda:\n",
"location": {
"index": 110
}
}
}
]
def batchExecute(self, verbose=False):
result = self.service['docs'].documents().batchUpdate(documentId=self.documentId, body={'requests': self.doc_body}).execute()
print("batchExecute", result)
if verbose:
print(json.dumps(result,indent=2))
doc = Report('1rgsEG5ZtPrf3q87GjItDM9dWEB5veCkD4dgzHKiVOL0')
doc.batchExecute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment