How to use the starthinker.util.sheets.sheets_read 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 / video / run.py View on Github external
def videos_from_sheets(sheets):
  rows = sheets_read(project.task['auth'], sheets['sheet'], sheets['tab'], "A3:Y")
  return rows_to_videos(rows)
github google / starthinker / starthinker / task / traffic / feed.py View on Github external
def _get_feed(self):
    """Fetches the feed based on initialization parameters.

    Returns:
      List of lists that represents the rows and columns of the feed. If the
      feed isn't found returns a list with an empty list.
    """

    if self.feed_name in self._feed_name_tab_map:
      for tab_name in self._feed_name_tab_map[self.feed_name]:
        for sheet in self.spreadsheet['sheets']:
          if sheet['properties']['title'] == tab_name:
            self.tab_name = tab_name
            return sheets_read(self.auth, self.trix_id, tab_name, self.trix_range)

    return [[]]
github google / starthinker / starthinker / task / sheets / run.py View on Github external
# append data if specified
  if 'append' in project.task:
    rows = get_rows(project.task['auth'], project.task['append'])
    sheets_write(
      project.task['auth'], 
      project.task['sheet'],
      project.task['tab'],
      project.task['range'],
      rows,
      append = True
    )

  # move data if specified
  # move data if specified
  if 'out' in project.task:
    rows = sheets_read(
      project.task['auth'],
      project.task['sheet'],
      project.task['tab'],
      project.task.get('range', 'A1')
    )

    if rows:
      schema = None

      # RECOMMENDED: define schema in json
      if project.task['out']['bigquery'].get('schema'):
        if project.verbose: print('SHEETS SCHEMA DEFINED')
        schema = project.task['out']['bigquery']['schema']

      # NOT RECOMMENDED: determine schema if missing 
      else:
github google / starthinker / starthinker / task / itp_audit / run.py View on Github external
{ "type": "STRING", "name": "Advertiser", "mode": "NULLABLE" }, 
      { "type": "INTEGER", "name": "Advertiser_Id", "mode": "NULLABLE" },
      { "type": "STRING", "name": "Campaign", "mode": "NULLABLE" }, 
      { "type": "INTEGER", "name": "Campaign_Id", "mode": "NULLABLE" },      
      { "type": "STRING", "name": "Insertion_Order", "mode": "NULLABLE" }, 
      { "type": "INTEGER", "name": "Insertion_Order_Id", "mode": "NULLABLE" },
      { "type": "STRING", "name": "Line_Item", "mode": "NULLABLE" }, 
      { "type": "INTEGER", "name": "Line_Item_Id", "mode": "NULLABLE" },
      { "type": "STRING", "name": "Line_Item_Type", "mode": "NULLABLE" },
      { "type": "INTEGER", "name": "Impressions", "mode": "NULLABLE" },
      { "type": "STRING", "name": "Segment1", "mode": "NULLABLE" }, 
      { "type": "STRING", "name": "Segment2", "mode": "NULLABLE" },      
      { "type": "STRING", "name": "Segment3", "mode": "NULLABLE" }
    ]

  sheet_rows = sheets_read('user', project.task['sheet'], 'DV3 Segments', a1_notation, retries=10)

  if not sheet_rows:
    sheet_rows = []

  print('DV360 SEGMENT SHEET TABLE WRITE')

  rows_to_table(
    auth='service',
    project_id=project.id,
    dataset_id=project.task['dataset'],
    table_id=DV360_CUSTOM_SEGMENTS_SHEET_TABLE,
    rows=sheet_rows,
    schema=schema,
    skip_rows=1,
    disposition='WRITE_TRUNCATE'
    )
github google / starthinker / starthinker / task / itp_audit / run.py View on Github external
def create_cm_site_segmentation(project):
  # Read sheet to bq table
  sheet_rows = sheets_read('user', project.task['sheet'], 'CM_Site_Segments', 'A:C', retries=10)
  if not sheet_rows:
    sheet_rows = []

  schema = [
    { "type": "STRING", "name": "Site_Dcm", "mode": "NULLABLE" }, 
    { "type": "INTEGER", "name": "Impressions", "mode": "NULLABLE" }, 
    { "type": "STRING", "name": "Site_Type", "mode": "NULLABLE" }
  ]

  rows_to_table(
    auth='service',
    project_id=project.id,
    dataset_id=project.task['dataset'],
    table_id=CM_SITE_SEGMENTATION_SHEET_TABLE,
    rows=sheet_rows,
    schema=schema,
github google / starthinker / starthinker / task / marketing / run.py View on Github external
def get_owners():
  if project.verbose: print 'GETTING OWNERS'

  owners = []

  if 'sheet' in project.task['owners']:
    owners = sheets_read(
      project.task['auth'],
      project.task['owners']['sheet']['url'],
      project.task['owners']['sheet']['tab'],
      project.task['owners']['sheet']['range']
    )
  elif 'bigquery' in project.task['owners']:
    owners = query_to_rows(
      project.task['auth'],
      project.id,
      project.task['owners']['bigquery']['dataset'],
      project.task['owners']['bigquery']['query']
    )

  # group account owners by email, create easy lookup sets for ids
  owners_grouped = {}
  for owner in owners:
github google / starthinker / starthinker / task / marketing / run.py View on Github external
def get_solutions():
  if project.verbose: print 'GETTING SCORES'

  for solution in project.task['solutions']:
    scores = []

    if 'sheet' in solution:
      scores = sheets_read(
        project.task['auth'],
        solution['sheet']['url'],
        solution['sheet']['tab'],
        solution['sheet']['range']
      )
    elif 'bigquery' in solution:
      scores = query_to_rows(
        project.task['auth'],
        project.id,
        solution['bigquery']['dataset'],
        solution['bigquery']['query']
      )

    # for easy lookup use dictionary
    solution['scores'] = {}
    for score in scores:
github google / starthinker / starthinker / task / marketing / run.py View on Github external
def get_impacts():
  if project.verbose: print 'GETTING IMPACTS'

  impacts = []

  if 'sheet' in project.task['impacts']:
    impacts = sheets_read(
      project.task['auth'],
      project.task['impacts']['sheet']['url'],
      project.task['impacts']['sheet']['tab'],
      project.task['impacts']['sheet']['range']
    )
  elif 'bigquery' in project.task['impacts']:
    impacts = query_to_rows(
      project.task['auth'],
      project.id,
      project.task['impacts']['bigquery']['dataset'],
      project.task['impacts']['bigquery']['query']
    )

  # for easy lookup use dictionary
  impacts = dict([(str(i[0]), float(i[1])) for i in impacts])