def extract_rate_limit(self, response):
        """Extract rate limit info from response/headers.
        
        The rate limit Twitter API request response provides bad data in the
        headers, so check the payload first and fallback to headers for other
        request types."""
        try:
            data = response.data['resources']['search']['/search/tweets']
            self.rate_limit_remaining = data['remaining']
            self.rate_limit_limit = data['limit']
            self.rate_limit_reset = epoch(data['reset']).datetime
        except (KeyError, __HOLE__):
            self.rate_limit_remaining = int(response.headers['x-rate-limit-remaining'])
            self.rate_limit_limit = int(response.headers['x-rate-limit-limit'])
            self.rate_limit_reset = epoch(int(response.headers['x-rate-limit-reset'])).datetime
        self.twitter_date = parse(response.headers['date']).datetime
        logging.debug(
            'Twitter rate limit info:: rate-limit: %s, remaining: %s, '\
            'reset: %s, current-time: %s' % (self.rate_limit_limit,
            self.rate_limit_remaining, self.rate_limit_reset, self.twitter_date))
dataset/ETHPy150Open Impactstory/total-impact-core/totalimpact/providers/twitter_paging.py/TwitterPager.extract_rate_limit