# A simple program that moves Finch forward when a certain piece of text is tweeted __author__="will_turnage" __date__ ="$Mar 27, 2013 2:12:12 PM$" import edu.cmu.ri.createlab.terk.robot.finch.Finch as Finch import twitter4j.TwitterStreamFactory as TwitterStreamFactory import twitter4j.conf as Conf import twitter4j.StatusListener as StatusListener import twitter4j.FilterQuery as FilterQuery # this class is called each time a tweet is posted that matches your hashtag class TwitterStatusListener(StatusListener): def onStatus(self, s): print s.getUser().getScreenName() + " " + s.getText() finch.setWheelVelocities(255, 255, 500) if __name__ == "__main__": # ask the user to enter a hashtag hashtag = raw_input("Enter hashtag: ") print "Preparing to search Twitter for '" + hashtag + "'" # go to dev.twitter.com and replace these values with values # for your own twitter app and login CONSUMER_KEY = "<insert your own key here>" CONSUMER_SECRET = "<insert your own secret here>" ACCESS_TOKEN = "<insert your own token here>" ACCESS_SECRET = "<insert your own secret>" # initiatlize your Twitter credentials cb = Conf.ConfigurationBuilder() cb.setOAuthConsumerKey(CONSUMER_KEY) cb.setOAuthConsumerSecret(CONSUMER_SECRET) cb.setOAuthAccessToken(ACCESS_TOKEN) cb.setOAuthAccessTokenSecret(ACCESS_SECRET) # initialize the finch finch = Finch() # create the object that listens to twitter listener = TwitterStatusListener() # create the internet stream that talks to Twitter stream = TwitterStreamFactory(cb.build()).getInstance() # connect the stream and the listener together stream.addListener(listener) # specify that you want the stream to only show tweets matching your hashtag stream.filter(FilterQuery(0, [], [hashtag]))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question