def get_tweets_iter(toolkit_collection, since, until, cap):
    """
    Returns a pymongo cursor to iterate over a maximum of `cap` tweets,
    between `since` and `until`. Uses sampling if there are really more
    tweets than `cap` in that period.
    """
    tweets = toolkit_collection.since(since).until(until)
    count = tweets.count()
    sample_rate = cap / count if count > cap else None
    if sample_rate:
        tweets = tweets.sample(sample_rate)
    return tweets
