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
getColoredStats.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录