示例#1
0
def start():
    listener = RuleListener()

    AUTH = {
        'consumer_key': '9ejfkiCu8dTMNDzF29cg',
        'consumer_secret': 'SicnRgAMXu31xvJnpJtqtGOZEZazhDynb7sXLPTnNo',
        'access_token': '14112449-ZDgvgw5Hgj1hf1sZFWP0VSBnJBMOiVhbhgpNDWd5n',
        'access_token_secret': 'ZMtTEXGZ5aNnGrMF03l0lSkqCaouo0CjJbEiN41QlO4'
    }

    rules = [Rule(track=["slim"], historical=True, on_status=[print_message])]
    listener.listen(rules=rules, **AUTH)
    def handle(self, *args, **options):
        """
        Get tweets and place them in our database of markov chains
        """
        listener = RuleListener()
        auth = getattr(settings, "TWITTER_AUTH", None)

        if auth is None:
            print "please add TWITTER_AUTH to your settings"
        else:
            # a very inclusive twitter stream to get lots of single lines
            rules = [Rule(track=["to","be","the","and"], on_status=[handle_tweets], operator="OR")]
            try:
                listener.listen(rules=rules, **auth)
            except KeyboardInterrupt:
                print "Captured %s tweets" % tweet_count 
                sys.exit()