def _iterate(self, url, **kwargs): """ Iterate over all pages for the given url. Feed in the result of self._build_path as the url. :param url: The url of the endpoint :type url: :py:class:`str` :param kwargs: The query string parameters kwargs['fields'] = [] kwargs['exclude_fields'] = [] kwargs['count'] = integer kwargs['offset'] = integer """ #fields as a kwarg ought to be a string with comma-separated substring #values to pass along to self._mc_client._get(). it also ought to #contain total_items whenever the kwarg is employed, this is enforced if 'fields' in kwargs: if not 'total_items' in kwargs['fields'].split(','): kwargs['fields'] += ',total_items' #Fetch results from mailchimp, up to first 100 result = self._mc_client._get(url=url, offset=0, count=100, **kwargs) total = result['total_items'] #Fetch further results if necessary if total > 100: for offset in range(1, int(total / 100) + 1): result = merge_results(result, self._mc_client._get( url=url, offset=int(offset*100), count=100, **kwargs )) return result else: # Further results not necessary return result
def _iterate(self, url, **queryparams): """ Iterate over all pages for the given url. Feed in the result of self._build_path as the url. :param url: The url of the endpoint :type url: :py:class:`str` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] queryparams['count'] = integer queryparams['offset'] = integer """ # fields as a query string parameter should be a string with # comma-separated substring values to pass along to # self._mc_client._get(). It should also contain total_items whenever # the parameter is employed, which is forced here. if 'fields' in queryparams: if 'total_items' not in queryparams['fields'].split(','): queryparams['fields'] += ',total_items' # Remove offset if provided in queryparams to avoid 'multiple values # for keyword argument' TypeError queryparams.pop("offset", None) # Fetch results from mailchimp, up to first count. If count is not # provided, return a count of 500. The maximum value supported by the # api is 1000, but such a large request can cause 504 errors. See: # https://github.com/VingtCinq/python-mailchimp/pull/207 count = queryparams.pop("count", 500) result = self._mc_client._get(url=url, offset=0, count=count, **queryparams) total = result['total_items'] # Fetch further results if necessary if total > count: for offset in range(1, int(total / count) + 1): result = merge_results( result, self._mc_client._get(url=url, offset=int(offset * count), count=count, **queryparams)) return result else: # Further results not necessary return result
async def _iterate(self, url, **queryparams): """ Iterate over all pages for the given url. Feed in the result of self._build_path as the url. :param url: The url of the endpoint :type url: :py:class:`str` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] queryparams['count'] = integer queryparams['offset'] = integer """ # fields as a query string parameter should be a string with # comma-separated substring values to pass along to # self._mc_client._get(). It should also contain total_items whenever # the parameter is employed, which is forced here. if 'fields' in queryparams: if 'total_items' not in queryparams['fields'].split(','): queryparams['fields'] += ',total_items' # Remove offset and count if provided in queryparams # to avoid 'multiple values for keyword argument' TypeError queryparams.pop("offset", None) queryparams.pop("count", None) # Fetch results from mailchimp, up to first 1000 result = await self._mc_client._get(url=url, offset=0, count=1000, **queryparams) total = result['total_items'] # Fetch further results if necessary if total > 1000: for offset in range(1, int(total / 1000) + 1): result = merge_results( result, await self._mc_client._get(url=url, offset=int(offset * 1000), count=1000, **queryparams)) return result else: # Further results not necessary return result
def _iterate(self, url, **kwargs): """ Iterate over all pages for the given url. Feed in the result of self._build_path as the url. :param url: The url of the endpoint :type url: :py:class:`str` :param kwargs: The query string parameters kwargs['fields'] = [] kwargs['exclude_fields'] = [] kwargs['count'] = integer kwargs['offset'] = integer """ #fields as a kwarg ought to be a string with comma-separated substring #values to pass along to self._mc_client._get(). it also ought to #contain total_items whenever the kwarg is employed, this is enforced if 'fields' in kwargs: if 'total_items' not in kwargs['fields'].split(','): kwargs['fields'] += ',total_items' # Remove offset and count if provided in kwargs # to avoid 'multiple values for keyword argument' TypeError offset = kwargs.pop("offset", 0) count = kwargs.pop("count", 5000) #Fetch results from mailchimp, up to first 5000 result = self._mc_client._get(url=url, offset=offset, count=count, **kwargs) total = result['total_items'] #Fetch further results if necessary if total > count: for offset in range(1, int(total / count) + 1): result = merge_results(result, self._mc_client._get( url=url, offset=int(offset*count), count=count, **kwargs )) return result else: # Further results not necessary return result