Answers for "tweepy stream tweets from user"

2

tweepy stream tweets from user

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
Posted by: Guest on January-04-2021
2

tweepy stream tweets from user

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
Posted by: Guest on January-04-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language