I am trying to create a listener for breaking news without including retweets but i get a syntax error when adding -is:retweet. see below image - what am i doing wrong???

listener = BasicTwitterListener(10)
listener.add_rules(tweepy.StreamRule(“breaking news”) -is:retweet)
listener.filter(expansions=[“author_id”], tweet_fields=[“created_at”])

You have a syntax error because the rule is not properly defined in python, the rule has to be a string, and you’re missing surrounding quotes, because you used quotes as part of the rule, and the ) parentheses is in the wrong place, try:

listener.add_rules(tweepy.StreamRule('"breaking news" -is:retweet'))

Note the rule is a string, enclosed by single quotes, because it contains double quotes.

3 Likes

OMG! Igor!!! I could love you forever! I have pulling my hair out over this for like 3 weeks now!

No problem! I would recommend using twarc for gathering data, instead of coding your own implementation, you can run twarc in a command line and specify the rules and run the stream and it will save the results and reconnect on errors etc for you: