From 1eb7ce3896df905c739f0ba0a29e218d5b7328a6 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Wed, 13 May 2020 12:26:06 -0400 Subject: [PATCH] fix gam info counts --- src/gam/gapi/directory/customer.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/gam/gapi/directory/customer.py b/src/gam/gapi/directory/customer.py index a25b7776..baae7088 100644 --- a/src/gam/gapi/directory/customer.py +++ b/src/gam/gapi/directory/customer.py @@ -69,19 +69,27 @@ def doGetCustomerInfo(): throw_reasons = [gapi.errors.ErrorReason.INVALID] while True: try: - usage = gapi.get_all_pages(rep.customerUsageReports(), - 'get', - 'usageReports', - throw_reasons=throw_reasons, - customerId=customerId, - date=tryDate, - parameters=parameters) - break + result = gapi.call(rep.customerUsageReports(), + 'get', + throw_reasons=throw_reasons, + customerId=customerId, + date=tryDate, + parameters=parameters) except gapi.errors.GapiInvalidError as e: tryDate = gapi_reports._adjust_date(str(e)) - if not usage: - print('No user count data available.') - return + continue + warnings = result.get('warnings', []) + fullDataRequired = ['accounts'] + usage = result.get('usageReports') + has_reports = bool(usage) + fullData, tryDate = gapi_reports._check_full_data_available( + warnings, tryDate, fullDataRequired, has_reports) + if fullData < 0: + print('No user report available.') + sys.exit(1) + if fullData == 0: + continue + break print(f'User counts as of {tryDate}:') for item in usage[0]['parameters']: api_name = user_counts_map.get(item['name'])