Search code examples
pythonfiltertweepy

How can I use multiple "filter"' with tweepy?


I'm a beginner on Python and am having an issue that I can't resolve on my first project using the API Tweepy. Here's the code :

count = 0
for tweet in tweepy.Cursor(api.search, q = "#mykeyword follow -filter:retweets filter:verified", tweet_mode='extended').items(10):
    count+=1
    print(f" Tweet n°{count}, Utilisateur = {tweet.user.name}, Tweet = {tweet.full_text}")

I would like this script to return the 10 last tweets containing the hashtag "mykeyword" and "follow" from verified accounts, filtering out every retweets. It works well when I keep either "-filter:retweets" or "filter:verified" but returns no results if I keep both, even though there should be some results. I have already tested some answers I found on Stackoverflow but most of them are quite outdated and the Tweepy documentation doesn't seem to cover my problem.

Does anyone have an idea about this matter ?

Thanks !


Solution

  • I just tried this convention

    filter:media AND -filter:retweets
    

    and it worked for my use case.