code: def get_tweets_count_times(twitter, count, query=None):
  r
      oldest_id, newest_id = _get_oldest_id(query=query)
      newest_id = newest_id or oldest_id
      all_tweets = []
      i = 0
      while i < count:
          i += 1
          if oldest_id <= newest_id:
              tweets = get_tweets(query=query, max_id=oldest_id - 1, count=TWEETS_PER_SEARCH, twitter=twitter)
          else:
              tweets = get_tweets(query=query, max_id=oldest_id - 1, since_id=newest_id, count=TWEETS_PER_SEARCH, twitter=twitter)
          rate_limit_remaining = twitter.get_lastfunction_header('x-rate-limit-remaining')
          rate_limit_reset = twitter.get_lastfunction_header('x-rate-limit-reset')
          if not len(tweets):
              oldest_id = oldest_id + ((newest_id or oldest_id) - oldest_id + 1) * 10000
              break
          elif isinstance(tweets, dict):
              print(tweets)
              break
          all_tweets.extend(tweets)
          tweet_ids = {t['id'] for t in tweets}
          if oldest_id:
              tweet_ids.add(oldest_id)
          oldest_id, newest_id = min(tweet_ids), max(tweet_ids)
          if rate_limit_remaining == 1:
              time.sleep(rate_limit_reset - time.time())
      save_tweets(all_tweets, query=query)
      _set_oldest_id(oldest_id, newest_id, query=query)
      if len(all_tweets) == 0:
          os.remove(make_oldest_id_path(query))
      return len(all_tweets), twitter.get_lastfunction_header('x-rate-limit-remaining')