getColoredStats.py 文件源码

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

项目:TwitterSentiment 作者: kalradivyanshu 项目源码 文件源码
def getSentiment(api, key):
    public_tweets = api.search(key)
    AvgSentiment = 0
    noOfTweets = len(public_tweets)
    sum1 = 0
    for tweet in public_tweets:
        text = tweet.text
        cleanedtext = ' '.join([word for word in text.split(' ') if len(word) > 0 and word[0] != '@' and word[0] != '#' and 'http' not in word and word != 'RT'])
        #print(cleanedtext)
        analysis = TextBlob(cleanedtext)
        sentiment = analysis.sentiment.polarity
        sum1 += sentiment

        if sentiment == 0:
            #ignore since not a opinion, its a general statement
            noOfTweets -= 1
    if noOfTweets > 0:
        AvgSentiment = sum1/noOfTweets
    return AvgSentiment
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号