How to use the starthinker.util.google_api.API_DBM 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 / dbm / __init__.py View on Github external
Bulletproofing: https://developers.google.com/bid-manager/v1/queries/getquery

  Args:
    * auth: (string) Either user or service.
    * report_id: (int) ID of DCm report to fetch ( either or name ).
    * name: (string) Name of report to fetch ( either or report_id ).

  Returns:
    * JSON definition of report.

  """


  if name:
    for query in API_DBM(auth, iterate=True).queries().listqueries().execute():
      if query['metadata']['title'] == name:
        return query
  else:
    return API_DBM(auth).queries().getquery(queryId=report_id).execute()
github google / starthinker / starthinker / util / dbm / __init__.py View on Github external
"endTimeMs": int((time.time() + (365 * 24 * 60 * 60)) * 1000), # 1 year in future
        "frequency": "DAILY",
        "nextRunMinuteOfDay": 4 * 60,
        "nextRunTimezoneCode": body['timezoneCode']
      }   

    # build report
    #pprint.PrettyPrinter().pprint(body)
    report = API_DBM(auth).queries().createquery(body=body).execute()

    # run report first time
    body = {
     "dataRange":report['metadata']['dataRange'],
     "timezoneCode":body['timezoneCode']
    }
    API_DBM(auth).queries().runquery(queryId=report['queryId'], body=body).execute()

  else:
    if project.verbose: print('DBM Report Exists:', body['metadata']['title'])

  return report
github google / starthinker / starthinker / task / dbm / helper.py View on Github external
rows = report_to_rows(report)
    rows = report_clean(rows)
    rows = rows_to_type(rows)
    print(json.dumps(get_schema(rows)[1], indent=2, sort_keys=True))

  # get sample
  elif project.args.sample:
    filename, report = report_file(auth, project.args.sample, None, 10)
    rows = report_to_rows(report)
    rows = report_clean(rows)
    rows = rows_to_type(rows)
    for r in rows_print(rows, row_min=0, row_max=20): pass

  # get list
  else:
    for report in API_DBM(auth, iterate=True).queries().listqueries().execute():
      print(json.dumps(report, indent=2, sort_keys=True))
github google / starthinker / starthinker / util / dbm / __init__.py View on Github external
Bulletproofing: https://developers.google.com/bid-manager/v1/queries/deletequery

  Args:
    * auth: (string) Either user or service.
    * report_id: (int) ID of DCm report to fetch ( either or name ).
    * name: (string) Name of report to fetch ( either or report_id ).

  Returns:
    * None

  """

  if project.verbose: print("DBM DELETE:", report_id or name)
  report = report_get(auth, report_id, name)
  if report:
    API_DBM(auth).queries().deletequery(queryId=report['queryId']).execute()
  else:
    if project.verbose: print('DBM DELETE: No Report')
github google / starthinker / starthinker / util / dbm / __init__.py View on Github external
* auth: (string) Either user or service.
    * report_id: (int) ID of DCm report to fetch ( either or name ).
    * name: (string) Name of report to fetch ( either or report_id ).

  Returns:
    * JSON definition of report.

  """


  if name:
    for query in API_DBM(auth, iterate=True).queries().listqueries().execute():
      if query['metadata']['title'] == name:
        return query
  else:
    return API_DBM(auth).queries().getquery(queryId=report_id).execute()
github google / starthinker / starthinker / util / dbm / __init__.py View on Github external
* dry_run (boolean) If set to True no write will occur, only a test of the upload for errors.
  
  Returns:
    * Results of upload.

  """

  header = [s['name'] for s in LineItem_Write_Schema]

  body = {
    "lineItems":'%s\n%s' % (','.join(header), rows_to_csv(rows).read()), # add header row
    "format":'CSV',
    "dryRun":dry_run
  }

  result = API_DBM(auth).lineitems().uploadlineitems(body=body).execute()
  #print(result)
  return(result)
github google / starthinker / starthinker / task / dbm / helper.py View on Github external
'''))

  # create parameters
  parser.add_argument('--report', help='report ID to pull json definition', default=None)
  parser.add_argument('--schema', help='report ID to pull schema format', default=None)
  parser.add_argument('--sample', help='report ID to pull sample data', default=None)
  parser.add_argument('--list', help='list reports', action='store_true')

  # initialize project
  project.from_commandline(parser=parser, arguments=('-u', '-c', '-s', '-v'))
  auth = 'service' if project.args.service else 'user'

  # get report
  if project.args.report:
    report = API_DBM(auth).queries().getquery(queryId=project.args.report).execute()
    print(json.dumps(report, indent=2, sort_keys=True))

  # get schema
  elif project.args.schema:
    filename, report = report_file(auth, project.args.schema, None, 10)
    rows = report_to_rows(report)
    rows = report_clean(rows)
    rows = rows_to_type(rows)
    print(json.dumps(get_schema(rows)[1], indent=2, sort_keys=True))

  # get sample
  elif project.args.sample:
    filename, report = report_file(auth, project.args.sample, None, 10)
    rows = report_to_rows(report)
    rows = report_clean(rows)
    rows = rows_to_type(rows)