question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to filter only tweets from original user with `stream.filter(follow=['12345'])`

See original GitHub issue

it looks like stream.filter(follow=['12345']) includes tweets at someone and RT, what’s the way to get tweets solely from that user?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

23reactions
nelvintancommented, Jun 1, 2018

Looking at Twitter’s API it seems like it is not possible to filter tweets from original user out.

My work around method:

  1. I created a function that checks whether the status object is from original creator or not.
  2. I will only print/save tweet if it is from the original creator.
def from_creator(status):
    if hasattr(status, 'retweeted_status'):
        return False
    elif status.in_reply_to_status_id != None:
        return False
    elif status.in_reply_to_screen_name != None:
        return False
    elif status.in_reply_to_user_id != None:
        return False
    else:
        return True
class MyStreamListener(tweepy.StreamListener):

    def on_status(self, status):
        if from_creator(status):
            try:
                # Prints out the tweet
                print(status.text)
                # Saves tweet into a file
                with open("Test.txt", 'a') as file:
                    file.write(status.text)
                return True
            except BaseException as e:
                print("Error on_data %s" % str(e))
            return True
        return True

    def on_error(self, status_code):
        if status_code == 420:
            print("Error 420")
            #returning False in on_error disconnects the stream
            return False
6reactions
sman-dkcommented, Apr 23, 2018

I had to write a few lines of code to filter it out my self. I did not find a solution for this in tweepy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Filtering Only Original Tweets in a tweepy.Stream
I'm not entirely sure what the problem is, but you can always try to simplify the logic in the is_not_a_reply method.
Read more >
Stream filtering Tweets from a large set of users - Twitter API v2
Hi, I am interested in a Filtered Stream that follows a predefined set of users. I am aiming for a set of a...
Read more >
Filtered stream introduction | Docs | Twitter Developer Platform
The filtered search endpoint supports edited Tweets. This endpoint will deliver edited Tweets that match one or more of your filters, along with...
Read more >
How to see only someone's original tweets on Twitter, filtering ...
That way you'll see what the user you are looking for tweeted from the ne...
Read more >
How to turn off retweets on Twitter from accounts you follow ...
Twitter lets users mute retweets from people they follow. ... from Twitter accounts you follow, so you only see original tweets from them....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found