Created
July 25, 2016 17:18
-
-
Save duner/9b824d5490821ee661d58533cd4e53ab to your computer and use it in GitHub Desktop.
MelaniaBot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oauthlib==1.1.2 | |
requests==2.10.0 | |
requests-oauthlib==0.6.2 | |
six==1.10.0 | |
tweepy==3.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import tweepy | |
auth = tweepy.OAuthHandler( | |
os.environ.get('TWITTER_CONSUMER_KEY'), | |
os.environ.get('TWITTER_CONSUMER_SECRET') | |
) | |
auth.set_access_token( | |
os.environ.get('TWITTER_ACCESS_TOKEN'), | |
os.environ.get('TWITTER_ACCESS_TOKEN_SECRET') | |
) | |
api = tweepy.API(auth) | |
class FLOTUSStreamListener(tweepy.StreamListener): | |
def on_status(self, status): | |
tweet_from_melania_bot(status.text) | |
return True | |
def on_connect(self): | |
print "Connected..." | |
return True | |
def on_timeout(self): | |
print 'Stream timeing out...' | |
return True | |
def tweet_from_melania_bot(status): | |
try: | |
status = api.update_status(status) | |
except: | |
pass | |
return status | |
def main(): | |
flotusStreamListener = FLOTUSStreamListener() | |
myStream = tweepy.Stream(auth=api.auth, listener=flotusStreamListener) | |
myStream.filter(follow=['flotus']) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment