Created
October 2, 2012 14:26
-
-
Save Rydgel/3819538 to your computer and use it in GitHub Desktop.
whosmad
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import tweepy | |
from tweepy.streaming import StreamListener | |
from tweepy import OAuthHandler | |
from tweepy import Stream | |
from tweepy.error import TweepError | |
import json | |
CONSUMER_KEY = "" | |
CONSUMER_SECRET = "" | |
OAUTH_TOKEN = "" | |
OAUTH_SECRET = "" | |
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(OAUTH_TOKEN, OAUTH_SECRET) | |
api = tweepy.API(auth) | |
class StdOutListener(StreamListener): | |
""" Whosmad """ | |
def on_data(self, data): | |
tweet = json.loads(data) | |
tweet_id = tweet['id_str'] | |
# envoi tweet | |
try: | |
api.retweet(id=tweet_id) | |
except TweepError: | |
print "can’t retweet (private or self)" | |
return True | |
def on_error(self, status): | |
print status | |
if __name__ == '__main__': | |
# launching stream | |
l = StdOutListener() | |
stream = Stream(auth, l) | |
stream.filter(track=['croivent', 'croive']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment