Mondrian Followers

Although my Mondrian-Twitter bot was a lot of fun to make and it entertains me when I see it post on Twitter, I realized that it wasn't really useful to others. I decided to make it better today by adding in some functionality to get it to follow people who mention "Mondrian" in a Twitter post.

Much like yesterday, the code for this was not too exciting. There are only about 5-6 lines more than what I already wrote that are shared below. The toughest part was just determining the appropriate way to navigate the incoming .json from posts to get the user's screen name to follow. After that, the program was essentially just like examples. The key part of the code is the line with newFollower=status.author.screen_name.

class myStreamListener(tweepy.StreamListener):
def on_status(self,status):
    newFollower = status.author.screen_name
    api.create_friendship(newFollower)
    print(status.author.screen_name)

myStreamListener = myStreamListener()
myStream = tweepy.Stream(auth=api.auth,listener = myStreamListener)

myStream.filter(track=['abstract art', 'mondrian'],async=True)