def main(argv):
  # Authenticate and construct service.
  service, config, flags = shopping_common.init(
      argv, __doc__, parents=[argparser])
  merchant_id = config['merchantId']
  account_id = flags.account_id

  if merchant_id != account_id:
    shopping_common.check_mca(
        config,
        True,
        msg='Non-multi-client accounts can only get their own information.')

  status = service.accounttax().get(
      merchantId=merchant_id, accountId=merchant_id).execute()
  print('Account %s:' % status['accountId'])
  if shopping_common.json_absent_or_false(status, 'rules'):
    print('- No tax settings, so no tax is charged.')
  else:
    print('- Found %d tax rules:' % len(status['rules']))
    for issue in status['rules']:
      if not shopping_common.json_absent_or_false(issue, 'ratePercent'):
        print('  - For %s in %s: %s%%' %
              (issue['locationId'], issue['country'], issue['ratePercent']))
      if not shopping_common.json_absent_or_false(issue, 'useGlobalRate'):
        print('  - For %s in %s: using the global tax table rate.' %
              (issue['locationId'], issue['country']))
      if not shopping_common.json_absent_or_false(issue, 'shippingTaxed'):
        print('   NOTE: Shipping charges are also taxed.')
Exemplo n.º 2
0
def main(argv):
  # Authenticate and construct service.
  service, config, flags = shopping_common.init(
      argv, __doc__, parents=[argparser])
  merchant_id = config['merchantId']
  account_id = flags.account_id

  if merchant_id != account_id:
    shopping_common.check_mca(
        config,
        True,
        msg='Non-multi-client accounts can only get their own information.')

  try:
    status = service.accountstatuses().get(
        merchantId=merchant_id, accountId=merchant_id).execute()
    print 'Account %s:' % status['accountId']
    if shopping_common.json_absent_or_false(status, 'dataQualityIssues'):
      print '- No data quality issues.'
    else:
      print(
          '- Found %d data quality issues:' % len(status['dataQualityIssues']))
      for issue in status['dataQualityIssues']:
        print '  - (%s) [%s]' % (issue['severity'], issue['id'])
        if shopping_common.json_absent_or_false(issue, 'exampleItems'):
          print '  - No example items.'
        else:
          print('  - Have %d examples from %d affected items:' %
                (len(issue['exampleItems']), issue['numItems']))
          for example in issue['exampleItems']:
            print '    - %s: %s' % (example['itemId'], example['title'])
  except client.AccessTokenRefreshError:
    print('The credentials have been revoked or expired, please re-run the '
          'application to re-authorize')
Exemplo n.º 3
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = shopping_common.init(argv,
                                                  __doc__,
                                                  parents=[argparser])
    merchant_id = config['merchantId']
    product_id = flags.product_id
    shopping_common.check_mca(config, False)

    try:
        status = service.productstatuses().get(merchantId=merchant_id,
                                               productId=product_id).execute()

        print('- Product "%s" with title "%s":' %
              (status['productId'], status['title']))
        if shopping_common.json_absent_or_false(status, 'dataQualityIssues'):
            print '    No data quality issues.'
        else:
            print 'Found %d data quality issues:' % len(
                status['dataQualityIssues'])
            for issue in status['dataQualityIssues']:
                if shopping_common.json_absent_or_false(issue, 'detail'):
                    print '    - (%s) [%s]' % (issue['severity'], issue['id'])
                else:
                    print('    - (%s) [%s] %s' %
                          (issue['severity'], issue['id'], issue['detail']))
    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']
    shopping_common.check_mca(config, True)

    try:
        request = service.accounts().list(merchantId=merchant_id,
                                          maxResults=MAX_PAGE_SIZE)

        while request is not None:
            result = request.execute()
            if shopping_common.json_absent_or_false(result, 'resources'):
                print 'No accounts were found.'
            else:
                accounts = result['resources']
                for account in accounts:
                    print('Account "%s" with name "%s" was found.' %
                          (account['id'], account['name']))

                request = service.accounts().list_next(request, result)
                break

    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
def main(argv):
  # Authenticate and construct service.
  service, config, flags = shopping_common.init(
      argv, __doc__, parents=[argparser])
  merchant_id = config['merchantId']
  account_id = flags.account_id

  if not account_id:
    account_id = merchant_id
  elif merchant_id != account_id:
    shopping_common.check_mca(
        config,
        True,
        msg='Non-multi-client accounts can only get their own information.')

  status = service.accountstatuses().get(
      merchantId=merchant_id, accountId=merchant_id).execute()
  print('Account %s:' % status['accountId'])
  if shopping_common.json_absent_or_false(status, 'dataQualityIssues'):
    print('- No data quality issues.')
  else:
    print('- Found %d data quality issues:' % len(status['dataQualityIssues']))
    for issue in status['dataQualityIssues']:
      print('  - (%s) [%s]' % (issue['severity'], issue['id']))
      if shopping_common.json_absent_or_false(issue, 'exampleItems'):
        print('  - No example items.')
      else:
        print('  - Have %d examples from %d affected items:' %
              (len(issue['exampleItems']), issue['numItems']))
        for example in issue['exampleItems']:
          print('    - %s: %s' % (example['itemId'], example['title']))
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']
    shopping_common.check_mca(config, True)

    try:
        name = 'account%s' % shopping_common.get_unique_id()
        account = {
            'name': name,
            'websiteUrl': 'https://%s.example.com/' % (name, )
        }

        # Add account.
        request = service.accounts().insert(merchantId=merchant_id,
                                            body=account)

        result = request.execute()

        print('Created account ID "%s" for MCA "%s".' %
              (result['id'], merchant_id))

    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']
    shopping_common.check_mca(config, False)

    request = service.productstatuses().list(merchantId=merchant_id,
                                             maxResults=MAX_PAGE_SIZE)

    while request is not None:
        result = request.execute()
        if shopping_common.json_absent_or_false(result, 'resources'):
            print('No products were found.')
            break
        else:
            statuses = result['resources']
            for status in statuses:
                print('- Product "%s" with title "%s":' %
                      (status['productId'], status['title']))
                if shopping_common.json_absent_or_false(
                        status, 'dataQualityIssues'):
                    print('  No data quality issues.')
                else:
                    print('  Found %d data quality issues:' %
                          len(status['dataQualityIssues']))
                    for issue in status['dataQualityIssues']:
                        if shopping_common.json_absent_or_false(
                                issue, 'detail'):
                            print('  - (%s) [%s]' %
                                  (issue['severity'], issue['id']))
                        else:
                            print('  - (%s) [%s] %s' %
                                  (issue['severity'], issue['id'],
                                   issue['detail']))
            request = service.productstatuses().list_next(request, result)
Exemplo n.º 8
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = shopping_common.init(argv,
                                                  __doc__,
                                                  parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id
    shopping_common.check_mca(config, True)

    request = service.accounts().delete(merchantId=merchant_id,
                                        accountId=account_id)
    request.execute()
    print('Account %s was deleted.' % account_id)
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']
    shopping_common.check_mca(config, True)

    name = 'account%s' % shopping_common.get_unique_id()
    account = {'name': name, 'websiteUrl': 'https://%s.example.com/' % name}

    # Add account.
    request = service.accounts().insert(merchantId=merchant_id, body=account)

    result = request.execute()

    print('Created sub-account ID %s for MCA %d.' %
          (result['id'], merchant_id))
Exemplo n.º 10
0
def main(argv):
  # Authenticate and construct service.
  service, config, flags = shopping_common.init(
      argv, __doc__, parents=[argparser])
  merchant_id = config['merchantId']
  account_id = flags.account_id
  shopping_common.check_mca(config, True)

  request = service.accounts().delete(
      merchantId=merchant_id, accountId=account_id)
  try:
    request.execute()
    print 'Account was deleted.'
  except client.AccessTokenRefreshError:
    print('The credentials have been revoked or expired, please re-run the '
          'application to re-authorize')
def main(argv):
    # Authenticate and construct service.
    service, config, flags = shopping_common.init(argv,
                                                  __doc__,
                                                  parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id
    shopping_common.check_mca(config, True)

    new_name = 'updated-account%s' % shopping_common.get_unique_id()
    request = service.accounts().patch(merchantId=merchant_id,
                                       accountId=account_id,
                                       body={'name': new_name})

    result = request.execute()
    print('Account with id %s was updated with new name "%s".' %
          (account_id, result['name']))
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']
    shopping_common.check_mca(config, True)

    try:
        request = service.accountstatuses().list(merchantId=merchant_id,
                                                 maxResults=MAX_PAGE_SIZE)

        while request is not None:
            result = request.execute()
            if shopping_common.json_absent_or_false(result, 'resources'):
                print 'No accounts were found.'
                break
            else:
                statuses = result['resources']
                for status in statuses:
                    print 'Account %s:' % status['accountId']
                    if shopping_common.json_absent_or_false(
                            status, 'dataQualityIssues'):
                        print '- No data quality issues.'
                    else:
                        print('- Found %d data quality issues:' %
                              len(status['dataQualityIssues']))
                        for issue in status['dataQualityIssues']:
                            print '  - (%s) [%s]' % (issue['severity'],
                                                     issue['id'])
                            if shopping_common.json_absent_or_false(
                                    issue, 'exampleItems'):
                                print '  - No example items.'
                            else:
                                print(
                                    '  - Have %d examples from %d affected items:'
                                    % (len(issue['exampleItems']),
                                       issue['numItems']))
                                for example in issue['exampleItems']:
                                    print '    - %s: %s' % (example['itemId'],
                                                            example['title'])
                request = service.accountstatuses().list_next(request, result)

    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
def main(argv):
    # Authenticate and construct service.
    service, config, flags = shopping_common.init(argv,
                                                  __doc__,
                                                  parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id

    if not account_id:
        account_id = merchant_id
    elif merchant_id != account_id:
        shopping_common.check_mca(
            config,
            True,
            msg='Non-multi-client accounts can only get their own information.'
        )

    settings = shippingsettings_sample.create_shippingsettings_sample()
    service.shippingsettings().update(merchantId=merchant_id,
                                      accountId=merchant_id,
                                      body=settings).execute()
    status = service.shippingsettings().get(merchantId=merchant_id,
                                            accountId=merchant_id).execute()
    print('Account %s:' % status['accountId'])
    if shopping_common.json_absent_or_false(status, 'postalCodeGroups'):
        print('- No postal code groups.')
    else:
        print('- %d postal code group(s):' % len(status['postalCodeGroups']))
    if shopping_common.json_absent_or_false(status, 'services'):
        print('- No services.')
    else:
        print('- %d service(s):' % len(status['services']))
        for service in status['services']:
            print('  Service "%s":' % service['name'])
            print('  - Delivery country: %s' % service['deliveryCountry'])
            print('  - Currency: %s' % service['currency'])
            print('  - Active: %s' % service['active'])
            print('  - Delivery time: %d - %d days' %
                  (service['deliveryTime']['minTransitTimeInDays'],
                   service['deliveryTime']['maxTransitTimeInDays']))
            if shopping_common.json_absent_or_false(service, 'rateGroups'):
                print('  - No rate groups.')
            else:
                print('  - %d rate groups.' % len(service['rateGroups']))
Exemplo n.º 14
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = shopping_common.init(argv,
                                                  __doc__,
                                                  parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id

    if merchant_id != account_id:
        shopping_common.check_mca(
            config,
            True,
            msg='Non-multi-client accounts can only get their own information.'
        )

    try:
        status = service.shippingsettings().get(
            merchantId=merchant_id, accountId=merchant_id).execute()
        print 'Account %s:' % status['accountId']
        if shopping_common.json_absent_or_false(status, 'postalCodeGroups'):
            print '- No postal code groups.'
        else:
            print '- %d postal code group(s):' % len(
                status['postalCodeGroups'])
        if shopping_common.json_absent_or_false(status, 'services'):
            print '- No services.'
        else:
            print '- %d service(s):' % len(status['services'])
            for service in status['services']:
                print '  Service "%s":' % service['name']
                print '  - Delivery country: %s' % service['deliveryCountry']
                print '  - Currency: %s' % service['currency']
                print '  - Active: %s' % service['active']
                print('  - Delivery time: %d - %d days' %
                      (service['deliveryTime']['minTransitTimeInDays'],
                       service['deliveryTime']['maxTransitTimeInDays']))
                if shopping_common.json_absent_or_false(service, 'rateGroups'):
                    print '  - No rate groups.'
                else:
                    print '  - %d rate groups.' % len(service['rateGroups'])
    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
Exemplo n.º 15
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = shopping_common.init(argv,
                                                  __doc__,
                                                  parents=[argparser])
    merchant_id = config['merchantId']
    account_id = flags.account_id

    if merchant_id != account_id:
        shopping_common.check_mca(
            config,
            True,
            msg='Non-multi-client accounts can only set their own information.'
        )

    try:
        settings = accounttax_sample.create_accounttax_sample(account_id)
        status = service.accounttax().update(merchantId=merchant_id,
                                             accountId=merchant_id,
                                             body=settings).execute()
        print 'Account %s:' % status['accountId']
        if shopping_common.json_absent_or_false(status, 'rules'):
            print '- No tax settings, so no tax is charged.'
        else:
            print('- Found %d tax rules:' % len(status['rules']))
            for issue in status['rules']:
                if not shopping_common.json_absent_or_false(
                        issue, 'ratePercent'):
                    print('  - For %s in %s: %s%%' %
                          (issue['locationId'], issue['country'],
                           issue['ratePercent']))
                if not shopping_common.json_absent_or_false(
                        issue, 'useGlobalRate'):
                    print(
                        '  - For %s in %s: using the global tax table rate.' %
                        (issue['locationId'], issue['country']))
                if not shopping_common.json_absent_or_false(
                        issue, 'shippingTaxed'):
                    print '   NOTE: Shipping charges are also taxed.'
    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']
    shopping_common.check_mca(config, False)

    try:
        request = service.productstatuses().list(merchantId=merchant_id,
                                                 maxResults=MAX_PAGE_SIZE)

        while request is not None:
            result = request.execute()
            if shopping_common.json_absent_or_false(result, 'resources'):
                print 'No products were found.'
            else:
                statuses = result['resources']
                for status in statuses:
                    print('- Product "%s" with title "%s":' %
                          (status['productId'], status['title']))
                    if shopping_common.json_absent_or_false(
                            status, 'dataQualityIssues'):
                        print '  No data quality issues.'
                    else:
                        print('  Found %d data quality issues:' %
                              len(status['dataQualityIssues']))
                        for issue in status['dataQualityIssues']:
                            if shopping_common.json_absent_or_false(
                                    issue, 'detail'):
                                print '  - (%s) [%s]' % (issue['severity'],
                                                         issue['id'])
                            else:
                                print('  - (%s) [%s] %s' %
                                      (issue['severity'], issue['id'],
                                       issue['detail']))
                request = service.productstatuses().list_next(request, result)
                break

    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
Exemplo n.º 17
0
def main(argv):
  # Authenticate and construct service.
  service, config, flags = shopping_common.init(
      argv, __doc__, parents=[argparser])
  merchant_id = config['merchantId']
  account_id = flags.account_id
  shopping_common.check_mca(config, True)

  try:
    new_name = 'updated-account%s' % (shopping_common.get_unique_id(),)
    request = service.accounts().patch(merchantId=merchant_id,
                                       accountId=account_id,
                                       body={'name': new_name})

    result = request.execute()
    print ('Account with id "%s" was updated with new name "%s".' %
           (account_id, result['name']))

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')
Exemplo n.º 18
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = shopping_common.init(argv,
                                                  __doc__,
                                                  parents=[argparser])
    merchant_id = config['merchantId']
    account_ids = flags.account_ids
    shopping_common.check_mca(config, True)

    batch = BatchHttpRequest(callback=account_deleted)

    for account_id in account_ids:
        # Add account deletion to the batch.
        batch.add(service.accounts().delete(merchantId=merchant_id,
                                            accountId=account_id))
    try:
        batch.execute()
    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
Exemplo n.º 19
0
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']
    shopping_common.check_mca(config, True)

    account_names = [
        'account%s' % shopping_common.get_unique_id()
        for i in range(BATCH_SIZE)
    ]
    batch = {
        'entries': [{
            'batchId': i,
            'merchantId': merchant_id,
            'method': 'insert',
            'account': {
                'name': v,
                'websiteUrl': 'https://%s.example.com/' % v,
            },
        } for i, v in enumerate(account_names)],
    }

    request = service.accounts().custombatch(body=batch)
    result = request.execute()

    if result['kind'] == 'content#accountsCustomBatchResponse':
        for entry in result['entries']:
            if not shopping_common.json_absent_or_false(entry, 'account'):
                account = entry['account']
                print('Account %s with name "%s" was created.' %
                      (account['id'], account['name']))
            elif not shopping_common.json_absent_or_false(entry, 'errors'):
                print('Errors for batch entry %d:' % entry['batchId'])
                print(
                    json.dumps(entry['errors'],
                               sort_keys=True,
                               indent=2,
                               separators=(',', ': ')))
    else:
        print('There was an error. Response: %s' % result)
Exemplo n.º 20
0
def main(argv):
    # Authenticate and construct service.
    service, config, _ = shopping_common.init(argv, __doc__)
    merchant_id = config['merchantId']
    shopping_common.check_mca(config, True)

    batch = BatchHttpRequest(callback=account_inserted)

    for _ in range(BATCH_SIZE):
        name = 'account%s' % shopping_common.get_unique_id()
        account = {
            'name': name,
            'websiteUrl': 'https://%s.example.com/' % (name, )
        }
        # Add account to the batch.
        batch.add(service.accounts().insert(merchantId=merchant_id,
                                            body=account))
    try:
        batch.execute()
    except client.AccessTokenRefreshError:
        print(
            'The credentials have been revoked or expired, please re-run the '
            'application to re-authorize')
Exemplo n.º 21
0
def main(argv):
    # Authenticate and construct service.
    service, config, flags = shopping_common.init(argv,
                                                  __doc__,
                                                  parents=[argparser])
    merchant_id = config['merchantId']
    account_ids = flags.account_ids
    shopping_common.check_mca(config, True)

    batch = {
        'entries': [{
            'batchId': i,
            'merchantId': merchant_id,
            'method': 'delete',
            'accountId': v,
        } for i, v in enumerate(account_ids)],
    }

    request = service.accounts().custombatch(body=batch)
    result = request.execute()

    if result['kind'] == 'content#accountsCustomBatchResponse':
        entries = result['entries']
        for entry in entries:
            if not shopping_common.json_absent_or_false(entry, 'errors'):
                print('Errors for batch entry %d:' % entry['batchId'])
                print(
                    json.dumps(entry['errors'],
                               sort_keys=True,
                               indent=2,
                               separators=(',', ': ')))
            else:
                print('Account %s deleted (batch entry %d).' %
                      (account_ids[entry['batchId']], entry['batchId']))
    else:
        print('There was an error. Response: %s' % result)