def startProducing(self): send = make_send(self) topics = [] track = [] for terms, tag in self.node['_topics']: topics.append((tag, [ x.lower().split() for x in terms ])) track.extend( x.split(None, 1)[0] for x in terms ) class Consumer(TwistedTwitterStream.TweetReceiver): def connectionFailed(this, why): log(self, 'connection failed (%s)' % why) def tweetReceived(this, data): if 'delete' not in data: text = data['text'].lower() for tag, kws in topics: if any( all( w in text for w in kw ) for kw in kws ): send(dict(tweet=data, word=tag)) TwistedTwitterStream.filter(TWITTER_USER, TWITTER_PASSWORD, Consumer(), track=track)
#!/usr/bin/env python # coding: utf-8 # # follow is a list of user IDs, not screen names # use something like this to get user IDs: # # screen_name = "BarackObama" # fd = urllib.urlopen("http://twitter.com/users/show/%s.json" % screen_name) # doc = simplejson.loads(fd.read()) # fd.close() # print doc.get("id") import TwistedTwitterStream from twisted.internet import reactor class consumer(TwistedTwitterStream.TweetReceiver): def connectionMade(self): print "connected..." def connectionFailed(self, why): print "cannot connect:", why reactor.stop() def tweetReceived(self, tweet): print "new tweet:", repr(tweet) if __name__ == "__main__": TwistedTwitterStream.filter("username", "password", consumer(), follow=["101010", "202020", "303030", "404040"]) reactor.run()
import TwistedTwitterStream from twisted.internet import reactor class consumer(TwistedTwitterStream.TweetReceiver): def connectionMade(self): print "connected..." def connectionFailed(self, why): print "cannot connect:", why reactor.stop() def tweetReceived(self, tweet): print "new tweet:", repr(tweet) if __name__ == "__main__": TwistedTwitterStream.filter("username", "password", consumer(), follow=["101010", "202020", "303030", "404040"]) reactor.run() ########NEW FILE######## __FILENAME__ = sample #!/usr/bin/env python # coding: utf-8 import TwistedTwitterStream from twisted.internet import reactor class consumer(TwistedTwitterStream.TweetReceiver): def connectionMade(self): print "connected..." def connectionFailed(self, why):
#!/usr/bin/env python # coding: utf-8 import TwistedTwitterStream from twisted.internet import reactor class consumer(TwistedTwitterStream.TweetReceiver): def connectionMade(self): print "connected..." def connectionFailed(self, why): print "cannot connect:", why reactor.stop() def tweetReceived(self, tweet): print "new tweet:", repr(tweet) # you may call self.disconnect() anytime to # permanently disconnect from the Twitter Stream if __name__ == "__main__": TwistedTwitterStream.filter( "username", "password", consumer(), track=["football", "soccer", "world cup", "palmeiras"]) reactor.run()
# # screen_name = "BarackObama" # fd = urllib.urlopen("http://twitter.com/users/show/%s.json" % screen_name) # doc = simplejson.loads(fd.read()) # fd.close() # print doc.get("id") import TwistedTwitterStream from twisted.internet import reactor class consumer(TwistedTwitterStream.TweetReceiver): def connectionMade(self): print "connected..." def connectionFailed(self, why): print "cannot connect:", why reactor.stop() def tweetReceived(self, tweet): print "new tweet:", repr(tweet) if __name__ == "__main__": TwistedTwitterStream.filter( "username", "password", consumer(), follow=["101010", "202020", "303030", "404040"]) reactor.run()
class consumer(TwistedTwitterStream.TweetReceiver): def connectionMade(self): print "connected..." def connectionFailed(self, why): print "cannot connect:", why reactor.stop() def tweetReceived(self, tweet): print "new tweet:", repr(tweet) form = urllib.urlencode({"value": tweet}) d = client.getPage( "http://localhost:8888/q/twitter", method="POST", postdata=form, headers={"Content-Type": "application/x-www-form-urlencoded"}, ) def err(w): print "E: ", w d.addErrback(err) if __name__ == "__main__": TwistedTwitterStream.filter("username", "pass", consumer(), track=["fail"]) reactor.run()
#!/usr/bin/env python # coding: utf-8 import TwistedTwitterStream from twisted.internet import reactor class consumer(TwistedTwitterStream.TweetReceiver): def connectionMade(self): print "connected..." def connectionFailed(self, why): print "cannot connect:", why reactor.stop() def tweetReceived(self, tweet): print "new tweet:", repr(tweet) # you may call self.disconnect() anytime to # permanently disconnect from the Twitter Stream if __name__ == "__main__": TwistedTwitterStream.filter("username", "password", consumer(), track=["football", "soccer", "world cup", "palmeiras"]) reactor.run()