ckoepp/TwitterSearch

tso.set_count(5)

Opened this issue · 3 comments

tso.set_count(5)
is not working on my side:

try:
    tso = TwitterSearchOrder()
    tso.set_keywords(['Lucca'])
    tso.set_count(5)
    tso.set_result_type('recent')
#    tso.set_until(datetime.date(2016, 04, 27))
#    tso.set_until(datetime.date(datetime.now()))


    ts = TwitterSearch(
        consumer_key = 'xxx',
        consumer_secret = 'xxx',
        access_token = 'xxxx,
        access_token_secret = 'xxxx'
     )

    for tweet in ts.search_tweets_iterable(tso):

        print tweet['entities']['media'][0]['media_url_https']

except TwitterSearchException as e: # take care of all those ugly errors if there are some
    print(e)

it's reporting hundred of results.

Thanks for opening this issue.

As far as I see it, TwitterSearch works as intended here. The count argument does not limit the number of tweets you'll see in your use case. It does limit the number of tweets you'll receive within a single request, though.

In other words: if you're using it within the for-loop you'll only increase the overhead as the lib will simply do more queries to fetch all tweets. If you're sure you'll only need five tweets, you can still set the parameter and leave the for-loop after receiving all tweets you need. By doing so, you'll limit the overhead to a minimum.

Hope this answers the confusion and I guess we should add this point to the documentation as you can get confused easily by the name of the parameter 😄

Hi,

Thanks for your replay, yes this clarify the point.

Anyway would be useful to include also a limit for each request, this could save bandwidth if we are performing frequent requests

There is already a statistical feature available. Just use the getStatistics() method of the TwitterSearch class.

All you need to do is a simple check against the amount of queries. If 5 queries or 1000 tweets are enough for you, just use break within the foreach-loop.

Although we could also implement a kind of limit feature within the TwitterSearch class to automatically break the loop.