happierfuntokenizing.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:user-factor-adaptation 作者: StonyBrookNLP 项目源码 文件源码
def tokenize_random_tweet(self):
        """
        If the twitter library is installed and a twitter connection
        can be established, then tokenize a random tweet.
        """
        try:
            import twitter
        except ImportError:
            print "Apologies. The random tweet functionality requires the Python twitter library: http://code.google.com/p/python-twitter/"
        from random import shuffle
        api = twitter.Api()
        tweets = api.GetPublicTimeline()
        if tweets:
            for tweet in tweets:
                if tweet.user.lang == 'en':
                    return self.tokenize(tweet.text)
        else:
            raise Exception("Apologies. I couldn't get Twitter to give me a public English-language tweet. Perhaps try again")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号