How to use the starthinker.util.project.project.from_commandline 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 / task / bigquery / helper.py View on Github external
# get parameters
  parser = argparse.ArgumentParser(
    formatter_class=argparse.RawDescriptionHelpFormatter,
    description=textwrap.dedent('''\
      Command line to get table schema from BigQuery.
      This is a helper to help developers debug and create tables. 

      Example: `python helper.py --project [id] --dataset [name] --table [name] -s [credentials]`

  '''))

  parser.add_argument('--dataset', '-d', help='name of BigQuery dataset', default=None)
  parser.add_argument('--table', '-t', help='name of BigQuery table', default=None)

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

  # print schema
  print(json.dumps(table_to_schema(auth, project.id, project.args.dataset, project.args.table)['fields'], indent=2))
github google / starthinker / starthinker / task / lineitem / helper.py View on Github external
def main():

  parser = argparse.ArgumentParser(
    formatter_class=argparse.RawDescriptionHelpFormatter,
    description=textwrap.dedent('''\
      Command line interface for fetching line items via legacy API.
      Helps developers quickly debug lineitem issues or permissions access issues.

      Example: python helper.py [line item id] -u [user credentials]
  '''))

  parser = argparse.ArgumentParser()
  parser.add_argument('lineitem', help='lineitem ID to pull schema, or "list" to get index')

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

  # print lineitem
  for row in lineitem_read(auth, lineitems=[project.args.lineitem]):
    print(row)
github google / starthinker / starthinker / task / dbm / helper.py View on Github external
Examples:
        To get list of reports: python helper.py --list -u [user credentials path]
        To get report json: python helper.py --report [id] -u [user credentials path]
        To get report schema: python helper.py --schema [id] -u [user credentials path]
        To get report sample: python helper.py --sample [id] -u [user credentials path]

  '''))

  # 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
github google / starthinker / starthinker / task / dv360_beta / helper.py View on Github external
def main():
  parser = argparse.ArgumentParser(
    formatter_class=argparse.RawDescriptionHelpFormatter,
    description=textwrap.dedent('''\
      Command line utility to download and print line items from the DV360 Beta API.

      Example: python helper.py --advertiser 3721733 --user user.json
               python helper.py --advertiser 3721733 --service service.json
  '''))

  # lineitem list requires an advertiser id
  parser.add_argument('--advertiser', help='Advertiser ID to pull line items from.')

  # initialize project
  project.from_commandline(parser=parser, arguments=('-u', '-c', '-s', '-v'))

  # determine auth based on parameters
  auth = 'service' if project.args.service else 'user'

  # pull the line items
  lineitems =  API_DV360_Beta(auth, iterate=True).advertisers().lineItems().list(advertiserId=project.args.advertiser).execute()

  # print line items
  for lineitem in lineitems:
    print(json.dumps(lineitem, indent=2, sort_keys=True))
github google / starthinker / starthinker / task / google_api / helper.py View on Github external
- Pull a list of placements: 
          - https://developers.google.com/doubleclick-advertisers/v3.3/placements/list
          - python task/google_api/helper.py -api dfareporting -version v3.3 -function placements.list -kwargs '{ "profileId":2782211 }' -u [credentials path]
      
  '''))

  # get parameters
  parser.add_argument('-api', help='api to run, name of product api')
  parser.add_argument('-version', help='version of api')
  parser.add_argument('-function', help='function to call in api')
  parser.add_argument('-uri', help='function to call in api', default=None)
  parser.add_argument('-kwargs', help='kwargs to pass to function, json string of name:value pairs')
  parser.add_argument('--iterate', help='set to true to force iteration', action='store_true')

  # initialize project ( used to load standard credentials parameters )
  project.from_commandline(parser=parser, arguments=('-u', '-c', '-s', '-v'))

  # the api wrapper takes parameters as JSON
  job = { 
    "auth":'service' if project.args.service else 'user',
    "api":project.args.api,
    "version":project.args.version,
    "function":project.args.function,
    "uri":project.args.uri,
    "kwargs":json.loads(project.args.kwargs),
    "iterate":project.args.iterate,
  }

  # run the API call
  results = API(job).execute()

  # display results