Skip to content

chore: run black on samples #1788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 68 additions & 44 deletions samples/adexchangeseller/generate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'
__author__ = "[email protected] (Sérgio Gomes)"

import argparse
import sys
Expand All @@ -33,54 +33,78 @@
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument(
'--ad_client_id',
help='The ID of the ad client for which to generate a report')
argparser.add_argument(
'--report_id',
help='The ID of the saved report to generate')
"--ad_client_id", help="The ID of the ad client for which to generate a report"
)
argparser.add_argument("--report_id", help="The ID of the saved report to generate")


def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[argparser],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
# Authenticate and construct service.
service, flags = sample_tools.init(
argv,
"adexchangeseller",
"v1.1",
__doc__,
__file__,
parents=[argparser],
scope="https://www.googleapis.com/auth/adexchange.seller.readonly",
)

# Process flags and read their values.
ad_client_id = flags.ad_client_id
saved_report_id = flags.report_id

# Process flags and read their values.
ad_client_id = flags.ad_client_id
saved_report_id = flags.report_id
try:
# Retrieve report.
if saved_report_id:
result = (
service.reports()
.saved()
.generate(savedReportId=saved_report_id)
.execute()
)
elif ad_client_id:
result = (
service.reports()
.generate(
startDate="2011-01-01",
endDate="2011-08-31",
filter=["AD_CLIENT_ID==" + ad_client_id],
metric=[
"PAGE_VIEWS",
"AD_REQUESTS",
"AD_REQUESTS_COVERAGE",
"CLICKS",
"AD_REQUESTS_CTR",
"COST_PER_CLICK",
"AD_REQUESTS_RPM",
"EARNINGS",
],
dimension=["DATE"],
sort=["+DATE"],
)
.execute()
)
else:
argparser.print_help()
sys.exit(1)
# Display headers.
for header in result["headers"]:
print("%25s" % header["name"], end=" ")
print()

try:
# Retrieve report.
if saved_report_id:
result = service.reports().saved().generate(
savedReportId=saved_report_id).execute()
elif ad_client_id:
result = service.reports().generate(
startDate='2011-01-01', endDate='2011-08-31',
filter=['AD_CLIENT_ID==' + ad_client_id],
metric=['PAGE_VIEWS', 'AD_REQUESTS', 'AD_REQUESTS_COVERAGE',
'CLICKS', 'AD_REQUESTS_CTR', 'COST_PER_CLICK',
'AD_REQUESTS_RPM', 'EARNINGS'],
dimension=['DATE'],
sort=['+DATE']).execute()
else:
argparser.print_help()
sys.exit(1)
# Display headers.
for header in result['headers']:
print('%25s' % header['name'], end=' ')
print()
# Display results.
for row in result["rows"]:
for column in row:
print("%25s" % column, end=" ")
print()

# Display results.
for row in result['rows']:
for column in row:
print('%25s' % column, end=' ')
print()
except client.AccessTokenRefreshError:
print(
"The credentials have been revoked or expired, please re-run the "
"application to re-authorize"
)

except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')

if __name__ == '__main__':
main(sys.argv)
if __name__ == "__main__":
main(sys.argv)
135 changes: 79 additions & 56 deletions samples/adexchangeseller/generate_report_with_paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'
__author__ = "[email protected] (Sérgio Gomes)"

import argparse
import sys
Expand All @@ -40,61 +40,84 @@

# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('ad_client_id',
help='The ID of the ad client for which to generate a report')
argparser.add_argument(
"ad_client_id", help="The ID of the ad client for which to generate a report"
)


def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[argparser],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')

ad_client_id = flags.ad_client_id

try:
# Retrieve report in pages and display data as we receive it.
start_index = 0
rows_to_obtain = MAX_PAGE_SIZE
while True:
result = service.reports().generate(
startDate='2011-01-01', endDate='2011-08-31',
filter=['AD_CLIENT_ID==' + ad_client_id],
metric=['PAGE_VIEWS', 'AD_REQUESTS', 'AD_REQUESTS_COVERAGE',
'CLICKS', 'AD_REQUESTS_CTR', 'COST_PER_CLICK',
'AD_REQUESTS_RPM', 'EARNINGS'],
dimension=['DATE'],
sort=['+DATE'],
startIndex=start_index,
maxResults=rows_to_obtain).execute()

# If this is the first page, display the headers.
if start_index == 0:
for header in result['headers']:
print('%25s' % header['name'], end=' ')
print()

# Display results for this page.
for row in result['rows']:
for column in row:
print('%25s' % column, end=' ')
print()

start_index += len(result['rows'])

# Check to see if we're going to go above the limit and get as many
# results as we can.
if start_index + MAX_PAGE_SIZE > ROW_LIMIT:
rows_to_obtain = ROW_LIMIT - start_index
if rows_to_obtain <= 0:
break

if (start_index >= int(result['totalMatchedRows'])):
break

except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')

if __name__ == '__main__':
main(sys.argv)
# Authenticate and construct service.
service, flags = sample_tools.init(
argv,
"adexchangeseller",
"v1.1",
__doc__,
__file__,
parents=[argparser],
scope="https://www.googleapis.com/auth/adexchange.seller.readonly",
)

ad_client_id = flags.ad_client_id

try:
# Retrieve report in pages and display data as we receive it.
start_index = 0
rows_to_obtain = MAX_PAGE_SIZE
while True:
result = (
service.reports()
.generate(
startDate="2011-01-01",
endDate="2011-08-31",
filter=["AD_CLIENT_ID==" + ad_client_id],
metric=[
"PAGE_VIEWS",
"AD_REQUESTS",
"AD_REQUESTS_COVERAGE",
"CLICKS",
"AD_REQUESTS_CTR",
"COST_PER_CLICK",
"AD_REQUESTS_RPM",
"EARNINGS",
],
dimension=["DATE"],
sort=["+DATE"],
startIndex=start_index,
maxResults=rows_to_obtain,
)
.execute()
)

# If this is the first page, display the headers.
if start_index == 0:
for header in result["headers"]:
print("%25s" % header["name"], end=" ")
print()

# Display results for this page.
for row in result["rows"]:
for column in row:
print("%25s" % column, end=" ")
print()

start_index += len(result["rows"])

# Check to see if we're going to go above the limit and get as many
# results as we can.
if start_index + MAX_PAGE_SIZE > ROW_LIMIT:
rows_to_obtain = ROW_LIMIT - start_index
if rows_to_obtain <= 0:
break

if start_index >= int(result["totalMatchedRows"]):
break

except client.AccessTokenRefreshError:
print(
"The credentials have been revoked or expired, please re-run the "
"application to re-authorize"
)


if __name__ == "__main__":
main(sys.argv)
61 changes: 39 additions & 22 deletions samples/adexchangeseller/get_all_ad_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""
from __future__ import print_function

__author__ = '[email protected] (Sérgio Gomes)'
__author__ = "[email protected] (Sérgio Gomes)"

import sys

Expand All @@ -31,30 +31,47 @@


def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
# Authenticate and construct service.
service, flags = sample_tools.init(
argv,
"adexchangeseller",
"v1.1",
__doc__,
__file__,
parents=[],
scope="https://www.googleapis.com/auth/adexchange.seller.readonly",
)

try:
# Retrieve ad client list in pages and display data as we receive it.
request = service.adclients().list(maxResults=MAX_PAGE_SIZE)
try:
# Retrieve ad client list in pages and display data as we receive it.
request = service.adclients().list(maxResults=MAX_PAGE_SIZE)

while request is not None:
result = request.execute()
ad_clients = result['items']
for ad_client in ad_clients:
print(('Ad client for product "%s" with ID "%s" was found. '
% (ad_client['productCode'], ad_client['id'])))
while request is not None:
result = request.execute()
ad_clients = result["items"]
for ad_client in ad_clients:
print(
(
'Ad client for product "%s" with ID "%s" was found. '
% (ad_client["productCode"], ad_client["id"])
)
)

print(('\tSupports reporting: %s' %
(ad_client['supportsReporting'] and 'Yes' or 'No')))
print(
(
"\tSupports reporting: %s"
% (ad_client["supportsReporting"] and "Yes" or "No")
)
)

request = service.adclients().list_next(request, result)
request = service.adclients().list_next(request, result)

except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
except client.AccessTokenRefreshError:
print(
"The credentials have been revoked or expired, please re-run the "
"application to re-authorize"
)

if __name__ == '__main__':
main(sys.argv)

if __name__ == "__main__":
main(sys.argv)
Loading