How to use the starthinker.util.project.project.task 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
}

Args: * auth: (string) Either user or service. * body: (json) the report body ( with or without filters ) * filters: (json) a dictionary of filters to apply ( see above examples )

Returns: * body: ( json ) modified report body """

new_body = body.copy()

for f, d in filters.items(): for v in get_rows(project.task['auth'], d): new_body['params'].setdefault('filters', []).append({"type": f, "value": v})

return new_body

github google / starthinker / starthinker / task / archive / run.py View on Github external
def archive():
  if project.verbose: print('ARCHIVE')

  day = project.date - timedelta(days=abs(project.task['days']))

  for object in object_list(
    project.task['auth'],
    project.task['storage']['bucket'] + ':' + project.task['storage']['path'],
    files_only=True, 
    raw=True
  ):
    object_day = datetime.strptime(object['updated'], '%Y-%m-%dT%H:%M:%S.%fZ').date()
    if object_day <= day:
      if project.task.get('delete', False) == False:
        if project.verbose: print('ARCHIVING FILE:', object['name'])
        object_move(
          project.task['auth'], 
          '%s:%s' % (object['bucket'], object['name']),
          '%s:archive/%s' % (object['bucket'], object['name'])
        )
      else:
        if project.verbose: print('DELETING FILE:', )
        object_delete(
          project.task['auth'],
github google / starthinker / starthinker / task / bucket / run.py View on Github external
@project.from_parameters
def bucket():
  if project.verbose: print "BUCKET", project.task['bucket']

  # create bucket
  bucket_create(project.task['auth'], project.id, project.task['bucket'])
  bucket_access(project.task['auth'], project.id, project.task['bucket'], emails=project.task.get('emails', []), groups=project.task.get('groups', []))
github google / starthinker / starthinker / task / marketing / run.py View on Github external
email.paragraph('Benefits')
    email.list(solution['Solution']['pitches'])

    # solution impact
    email.table(IMPACT_SCHEMA, [(i[0], '%d%%' % i[1]) for i in solution['Solution']['impacts'].items()])

    email.button('Learn More', project.task['link'], big=True)

  #print email.get_html()
 
  send_email(
    'user', 
    owner['Account Email'],
    project.task['email']['from'],
    project.task['email']['cc'],
    project.task['email']['subject'],
    email.get_text(),
    email.get_html()
  )
github google / starthinker / starthinker / task / bigquery / run.py View on Github external
project.task.get('schema', []),
      0
    )
      
  elif 'query' in project.task['from']:
    if 'table' in project.task['to']:
      if project.verbose: print("QUERY TO TABLE", project.task['to']['table'])

      if 'pre_process_query' in project.task['to']:
        print('executing statement')
        execute_statement(
            project.task['auth'],
            project.id,
            project.task['to']['dataset'],
            project.task['to']['pre_process_query'],
            use_legacy_sql=project.task['from'].get('legacy', project.task['from'].get('useLegacySql', True))
        )
      query_to_table(
        project.task['auth'],
        project.id,
        project.task['to']['dataset'],
        project.task['to']['table'],
        query_parameters(project.task['from']['query'], project.task['from'].get('parameters')),
        disposition = project.task['write_disposition'] if 'write_disposition' in project.task else 'WRITE_TRUNCATE',
        legacy=project.task['from'].get('legacy', project.task['from'].get('useLegacySql', True)), # DEPRECATED: useLegacySql,
        target_project_id=project.task['to'].get('project_id', project.id)
      )
    # NOT USED SO RIPPING IT OUT
    # Mauriciod: Yes, it is used, look at project/mauriciod/target_winrate.json
    elif 'storage' in project.task['to']:
      if project.verbose: print("QUERY TO STORAGE", project.task['to']['storage'])
      local_file_name = '/tmp/%s' % str(uuid.uuid1())
github google / starthinker / starthinker / task / sheets / run.py View on Github external
def sheets():
  if project.verbose: print('SHEETS')

  # if sheet or tab is missing, don't do anything
  if not project.task.get('sheet') or not project.task.get('tab'):
    if project.verbose: print('Missing Sheet and/or Tab, skipping task.')
    return

  # delete if specified, will delete sheet if no more tabs remain 
  if project.task.get('delete', False):
    sheets_tab_delete(
      project.task['auth'], 
      project.task['sheet'], 
      project.task['tab']
    )

  # create a sheet and tab if specified, if template
  if 'template' in project.task:
    sheets_create(
      project.task['auth'],
      project.task['sheet'],
github google / starthinker / starthinker / task / twitter / run.py View on Github external
if 'trends' in project.task:
    if 'places' in project.task['trends']: 
      rows = twitter_trends_places()
      project.task['out']['bigquery']['schema'] = TWITTER_TRENDS_PLACE_SCHEMA
      project.task['out']['bigquery']['skip_rows'] = 0
    elif 'closest' in project.task['trends']: 
      rows = twitter_trends_closest()
      project.task['out']['bigquery']['schema'] = TWITTER_TRENDS_CLOSEST_SCHEMA
      project.task['out']['bigquery']['skip_rows'] = 0
    else: 
      rows = twitter_trends_available()
      project.task['out']['bigquery']['schema'] = TWITTER_TRENDS_AVAILABLE_SCHEMA
      project.task['out']['bigquery']['skip_rows'] = 0

  if rows: put_rows(project.task['auth'], project.task['out'], rows)
github google / starthinker / starthinker / task / barnacle / run.py View on Github external
def get_sites(accounts):

  if project.verbose: print('DCM Sites')

  for account_id in accounts:
    is_superuser, profile_id = get_profile_for_api(project.task['auth'], account_id)
    kwargs = { 'profileId':profile_id, 'accountId':account_id } if is_superuser else { 'profileId':profile_id }
    for site in API_DCM("user", iterate=True, internal=is_superuser).sites().list(**kwargs).execute():
      if int(site['accountId']) in accounts: 

        for contact in site.get('siteContacts', []):
          SITE_CONTACTS.append([
            site['accountId'],
            site.get('subaccountId'),
            site.get('directorySiteId'),
            site['id'],
            contact['id'],
            contact['email'],
            contact.get('firstName', ''),
            contact.get('lastName', ''),
            contact.get('title', ''),
            contact.get('address', ''),