Skip to content

Instantly share code, notes, and snippets.

@Rydgel
Created October 2, 2012 14:26
Show Gist options
  • Save Rydgel/3819538 to your computer and use it in GitHub Desktop.
Save Rydgel/3819538 to your computer and use it in GitHub Desktop.
whosmad
#!/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