How to use the starthinker.util.google_api.API_Retry function in starthinker

To help you get started, we’ve selected a few starthinker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / starthinker / starthinker / util / bigquery / __init__.py View on Github external
def job_wait(auth, job):
  if job:
    if project.verbose: print('BIGQUERY JOB WAIT:', job['jobReference']['jobId'])

    request = API_BigQuery(auth).jobs().get(
      projectId=job['jobReference']['projectId'],
      jobId=job['jobReference']['jobId']
    )
  
    while True:
      sleep(5)
      if project.verbose: print('.', end='')
      sys.stdout.flush()
      result = API_Retry(request)
      if 'errors' in result['status']:
        raise Exception('BigQuery Job Error: %s' % ' '.join([e['message'] for e in result['status']['errors']]))
      elif 'errorResult' in result['status']: 
        raise Exception('BigQuery Job Error: %s' % result['status']['errorResult']['message'])
      elif result['status']['state'] == 'DONE':
        if project.verbose: print('JOB COMPLETE:', result['id'])
        break
github google / starthinker / util / sheets / __init__.py View on Github external
def sheets_batch_update(auth, sheet_url, data):
  service = get_service('sheets', 'v4', auth)
  sheet_id = sheets_id(sheet_url)
  API_Retry(service.spreadsheets().batchUpdate(spreadsheetId=sheet_id, body=data))
github google / starthinker / starthinker / util / sheets / __init__.py View on Github external
def sheets_tab_copy(auth, from_sheet_url_or_name, from_sheet_tab, to_sheet_url_or_name, to_sheet_tab, overwrite=False):
  if project.verbose: print('SHEETS COPY', from_sheet_url_or_name, from_sheet_tab, to_sheet_url_or_name, to_sheet_tab)
  service = get_service('sheets', 'v4', auth)

  # convert human readable to ids
  from_sheet_id, from_tab_id = sheets_tab_id(auth, from_sheet_url_or_name, from_sheet_tab)
  to_sheet_id, to_tab_id = sheets_tab_id(auth, to_sheet_url_or_name, to_sheet_tab)

  # overwrite only if does not exist
  if overwrite or to_tab_id is None:

    # copy tab between sheets, the name changes to be "Copy of [from_sheet_tab]"
    copy_sheet = API_Retry(service.spreadsheets().sheets().copyTo(spreadsheetId=from_sheet_id, sheetId=from_tab_id, body={
      "destinationSpreadsheetId": to_sheet_id,
    }))

    body = {
      "requests":[] 
    }

    # if destination tab exists, delete it
    if to_tab_id:
      body['requests'].append({
        "deleteSheet": {
          "sheetId": to_tab_id
        }
      })

    # change the copy name to the designated name, remove "Copy of "
github google / starthinker / starthinker / util / sheets / __init__.py View on Github external
def sheets_get(auth, sheet_url_or_name):
  sheet_id = sheets_id(auth, sheet_url_or_name)
  if sheet_id: 
    service = get_service('sheets', 'v4', auth)
    return API_Retry(service.spreadsheets().get(spreadsheetId=sheet_id))
  else: 
    return None
github google / starthinker / starthinker / util / sheets / __init__.py View on Github external
def sheets_clear(auth, sheet_url_or_name, sheet_tab, sheet_range):
  if project.verbose: print('SHEETS CLEAR', sheet_url_or_name, sheet_tab, sheet_range)
  service = get_service('sheets', 'v4', auth)
  sheet_id = sheets_id(auth, sheet_url_or_name)
  API_Retry(service.spreadsheets().values().clear(spreadsheetId=sheet_id, range=sheets_tab_range(sheet_tab, sheet_range), body={}))
github google / starthinker / util / email / __init__.py View on Github external
def get_email_links(auth, email_from, email_to, subject_regexp=None, link_regexp=None, download=False, date_min=None, date_max=None):
  if project.verbose: print 'GETTING EMAIL LINKS'
  service = get_service('gmail', 'v1', auth)
  messages = _email_find(service, email_from, email_to, date_min, date_max)
  subject_filter = re.compile(r'%s' % subject_regexp) if subject_regexp else None
  for message in messages:
    message = API_Retry(service.users().messages().get(userId='me', id=message['id']))
    if subject_filter is None or subject_filter.match(_get_subject(message)):
      yield _email_links(service, message, link_regexp, download)
github google / starthinker / starthinker / util / sheets / __init__.py View on Github external
def sheets_batch_update(auth, sheet_url_or_name, data):
  service = get_service('sheets', 'v4', auth)
  sheet_id = sheets_id(auth, sheet_url_or_name)
  API_Retry(service.spreadsheets().batchUpdate(spreadsheetId=sheet_id, body=data))