예제 #1
0
 def save(self, posts, subreddit_info, get_comments):
     total = 0
     for post in posts:
         post_sentiment = vader(post.selftext.encode('utf8'))
         message = RedditMessage(_id=post.id,
                                 text=post.selftext,
                                 date=datetime.utcfromtimestamp(
                                     post.created_utc),
                                 community=subreddit_info['name'],
                                 positive=post_sentiment['pos'],
                                 negative=post_sentiment['neg'],
                                 neutral=post_sentiment['neu'],
                                 score=post.score)
         comments = get_comments(post)
         for comment in comments:
             _sentiment = vader(comment.body.encode('utf8'))
             comment_message = RedditMessage(
                 text=comment.body,
                 date=datetime.utcfromtimestamp(comment.created_utc),
                 community=subreddit_info['name'],
                 positive=_sentiment['pos'],
                 negative=_sentiment['neg'],
                 neutral=_sentiment['neu'],
                 score=comment.score)
             # print comment
             comment_message.save()
             total += 1
         message.save()
         total += 1
     logger.info('{}: saved {} messages'.format(subreddit_info['name'],
                                                total))
예제 #2
0
def build_other_tweets(tweets):
    tweets_dict = {'tweets': [], 'sentiment_count': {'Positive': 0, 'Neutral': 0, 'Negative':0}}
    
    for tweet in tweets: #each tweet will be a Python dictionary
        text = tweet['text'].encode('ascii', 'ignore')
        text = ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)"," ",text).split())
        text.strip()

        if text == "":
            continue

        date = tweet['created_at'].encode('ascii', 'ignore')
        retweet_count = tweet['retweet_count']
        sentiment = vader(text)

        if sentiment['compound'] < -0.1:
            tweets_dict['sentiment_count']['Negative'] += 1
        elif sentiment['compound'] > 0.1:
            tweets_dict['sentiment_count']['Positive'] += 1
        else:
            tweets_dict['sentiment_count']['Neutral'] += 1

        tweet_data = {"text" : text, "date" : date, "retweet_count" : retweet_count, "sentiment" : sentiment}
        tweets_dict["tweets"].insert(0, tweet_data)

    return tweets_dict
예제 #3
0
	def happy_val(self):
		vs=vader(self.txt)
		if self.emoji=='':
			self.senti_val=vs['pos']-vs['neg']
		else:
			txt=vs['pos']-vs['neg']
			emoji=self.emoji_senti(self.emoji)
			self.senti_val=txt+emoji
예제 #4
0
    def compute_sentiment(text):
        """
        Get sentiment analysis scores for the given text.
        Args:
            text (str) : text on which sentiment analysis will be computed

        Returns:
            dictionary of sentiment scores
        """
        return vader(text.encode("utf8"))
예제 #5
0
 def save(self, post, community):
     post_sentiment = vader(post.text.encode('utf8'))
     message = TwitterMessage(
         _id=post.id_str,
         text=post.text,
         date=post.created_at,
         community=community,
         positive=post_sentiment['pos'],
         negative=post_sentiment['neg'],
         neutral=post_sentiment['neu'],
         score=post.retweet_count,
     )
     message.save()
     return
예제 #6
0
def build_tweets_dict(tweets):
    "builds tweets dictionary with raw tweeter tweets"
    tweets_dict = {'tweets': []}
    for tweet in tweets: #each tweet will be a Python dictionary
        text = tweet['text'].encode('ascii', 'ignore')
        text = ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)"," ",text).split())
        text.strip()

        if text == "":
            continue

        date = tweet['created_at'].encode('ascii', 'ignore')
        retweet_count = tweet['retweet_count']
        sentiment = vader(text)

        tweet_data = {"text" : text, "date" : date, "retweet_count" : retweet_count, "sentiment" : sentiment}
        tweets_dict["tweets"].insert(0, tweet_data)

    return tweets_dict
예제 #7
0
파일: server.py 프로젝트: rtrad/ssbm_tweet
 def _compute_sentiment(self, text):
     return vader(text.encode('utf8'))
예제 #8
0
if 'errors' in personalInfoResponse:
    error = personalInfoResponse['errors']
    print error[0]['message']
    if error[0]['code'] == 50:
        #user not found
        search_users(name_query)



realName = personalInfoResponse['name']
handle = personalInfoResponse['screen_name']
bio = personalInfoResponse['description']
profilePicture = personalInfoResponse['profile_image_url']
coverPhoto = personalInfoResponse['profile_banner_url']


pyDictionary = {'name' : realName, 'handle' : handle, 'bio' : bio, 'profilePicture' : profilePicture, 'coverPhoto' : coverPhoto, "tweets" : []}


for item in r: #each tweet will be a Python dictionary
    
    text = item['text'].encode('ascii', 'ignore')
    date = item['created_at'].encode('ascii', 'ignore')
    retweet_count = item['retweet_count']
    feels = vader(text)

    tempDict = {"text" : text, "date" : date, "retweet_count" : retweet_count, "feels" : feels}
    pyDictionary["tweets"].append(tempDict)
    
jsonObjectToPassToFront = json.dumps(pyDictionary) #this object is the output
print "Success!"