Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_advertisers(accounts):
if project.verbose: print('DCM Advertisers')
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 advertiser in API_DCM("user", iterate=True, internal=is_superuser).advertisers().list(**kwargs).execute():
if int(advertiser['accountId']) in accounts:
yield [
advertiser['accountId'],
advertiser.get('subaccountId'),
advertiser['id'],
advertiser.get('advertiserGroupId'),
advertiser['name'],
advertiser['status'],
advertiser.get('defaultEmail'),
advertiser.get('clickThroughUrlSuffix'),
advertiser.get('defaultClickThroughEventTagId'),
advertiser['suspended'],
advertiser['floodlightConfigurationId'],
advertiser['originalFloodlightConfigurationId'],
]
* auth: (string) Either user or service.
* account_id: (int) Account number for which report is retrieved.
Returns:
* Is Superuser ( bool ): True if superuser account
* Profile ID ( int ): profile id to be used to make API call
Raises:
* If current credentials do not have a profile for this account.
"""
profile_admin = None
profile_network = None
for p in API_DCM(auth, iterate=True).userProfiles().list().execute():
p_id = int(p['profileId'])
a_id = int(p['accountId'])
# take the first profile for admin
if a_id == 2515 and 'subAccountId' not in p:
profile_admin = p_id
break
# try to find a network profile if exists
if a_id == account_id:
profile_network = p_id
break
if profile_admin: return True, profile_admin
elif profile_network: return False, profile_network
else: raise Exception('Add your user profile to DCM account %s.' % account_id)
filename, report = report_file(auth, project.args.account, project.args.schema, None, 10)
rows = report_to_rows(report)
rows = report_clean(rows)
print(json.dumps(report_schema(next(rows)), indent=2, sort_keys=True))
# get sample
elif project.args.sample:
filename, report = report_file(auth, project.args.account, 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_DCM(auth, internal=is_superuser).reports().list(**kwargs).execute():
print(json.dumps(report, indent=2, sort_keys=True))
def dcm_api_list(endpoint):
accounts = set(get_rows("user", project.task['accounts']))
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 item in API_DCM(project.task['auth'], iterate=True, internal=is_superuser).call(endpoint).list(**kwargs).execute():
yield item
* account: (string) [account:advertiser@profile] token.
* 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
"""
report = report_get(auth, account, report_id, name)
if report:
account_id, advertiser_ids = parse_account(auth, account)
is_superuser, profile_id = get_profile_for_api(auth, account_id)
kwargs = { 'profileId':profile_id, 'accountId':account_id } if is_superuser else { 'profileId':profile_id }
kwargs['reportId'] = report['id']
API_DCM(auth, internal=is_superuser).reports().delete(**kwargs).execute()
else:
if project.verbose: print('DCM DELETE: No Report')
Args:
* auth: (string) Either user or service.
* account: (string) [account:advertiser@profile] token.
* floodlight_activity_id: (int) ID of DCM floodlight to upload conversions to.
* converstion_type: (string) One of the following: encryptedUserId, encryptedUserIdCandidates, gclid, mobileDeviceId.
* conversion_rows: (iterator) List of the following rows: Ordinal, timestampMicros, encryptedUserId | encryptedUserIdCandidates | gclid | mobileDeviceId.
* encryption_entity: (object) See EncryptionInfo docs: https://developers.google.com/doubleclick-advertisers/v3.2/conversions/batchinsert#encryptionInfo
"""
account_id, advertiser_id = parse_account(auth, account)
is_superuser, profile_id = get_profile_for_api(auth, account_id)
kwargs = { 'profileId':profile_id, 'accountId':account_id } if is_superuser else { 'profileId':profile_id }
kwargs['id'] = floodlight_activity_id
response = API_DCM(auth, internal=is_superuser).floodlightActivities().get(**kwargs).execute()
# upload in batch sizes of DCM_CONVERSION_SIZE
row_count = 0
row_buffer = []
for is_last, row in flag_last(conversion_rows):
row_buffer.append(row)
if is_last or len(row_buffer) == DCM_CONVERSION_SIZE:
if project.verbose: print('CONVERSION UPLOADING ROWS: %d - %d' % (row_count, row_count + len(row_buffer)))
body = {
'conversions': [{
'floodlightActivityId': floodlight_activity_id,
'floodlightConfigurationId': response['floodlightConfigurationId'],
'ordinal': row[0],
def get_accounts(accounts):
if project.verbose: print('DCM Accounts')
for account_id in accounts:
is_superuser, profile_id = get_profile_for_api(project.task['auth'], account_id)
kwargs = { 'profileId':profile_id, 'id':account_id }
account = API_DCM("user").accounts().get(**kwargs).execute()
yield [
account['id'],
account['name'],
account['active'],
account.get('description', ''),
id_to_timezone(account['reportsConfiguration']['reportGenerationTimeZoneId']),
account.get('currencyId'),
account.get('countryId'),
account['locale'],
account['nielsenOcrEnabled'],
account['shareReportsWithTwitter'],
]
def get_roles(accounts):
if project.verbose: print('DCM Roles')
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 role in API_DCM("user", iterate=True, internal=is_superuser).userRoles().list(**kwargs).execute():
if int(role['accountId']) in accounts:
if 'permissions' in role:
for permission in role['permissions']:
yield [
role['accountId'],
role.get('subaccountId'),
role['id'],
role['name'],
role['defaultUserRole'],
permission['name'],
permission['availability'],
]
else:
yield [
role['accountId'],
role.get('subaccountId'),
Args:
* auth: (string) Either user or service.
* account: (string) [account:advertiser@profile] token.
Returns:
* Profile ID.
Raises:
* If current credentials do not have a profile for this account.
"""
account_id, advertiser_ids = parse_account(auth, account)
is_superuser, profile_id = get_profile_for_api(auth, account_id)
response = API_DCM(auth, internal=is_superuser).accounts().get(id=account_id, profileId=profile_id).execute()
return response["name"]