public async Task <IActionResult> GetTweetsByHashTag(string hashtag)
        {
            var tweets = _twitterService.GetTweetListByHashtag(hashtag);

            var x = _twitterService.GetSentimentAnalysisForListOfTweetWithoutComments(tweets);

            return(Ok(x));
        }
Beispiel #2
0
        public IActionResult GetTweetsByLocationAsync([FromQuery] string hashtag, [FromQuery] int count, [FromQuery] double latitude, [FromQuery] double longitude)
        {
            //40.730610
            //-73.935242
            var tweets = Search.SearchTweets(new SearchTweetsParameters(hashtag)
            {
                SearchType             = SearchResultType.Recent,
                MaximumNumberOfResults = count,
                TweetSearchType        = TweetSearchType.All,
                GeoCode = new GeoCode(latitude, longitude, 50, DistanceMeasure.Kilometers)
            });

            var result = _twitterService.GetSentimentAnalysisForListOfTweetWithoutComments(tweets.ToList());

            if (result.Count != 0)
            {
                var neutral  = 0;
                var positive = 0;
                var negative = 0;

                foreach (var item in result)
                {
                    if (item.SentimentObjectModel.SentimentType.Equals("Neutral"))
                    {
                        neutral++;
                    }

                    if (item.SentimentObjectModel.SentimentType.Equals("Positive"))
                    {
                        positive++;
                    }

                    if (item.SentimentObjectModel.SentimentType.Equals("Negative"))
                    {
                        negative++;
                    }
                }
                var command = new AddHashtagHistoryCommand(new HashtagHistoryModel()
                {
                    HashtagValue             = hashtag,
                    NegativeSentimentCounter = negative,
                    PositiveSentimentCounter = positive,
                    NeutralSentimentCounter  = neutral
                });
                _commandDispatcher.Execute(command);
            }
            return(Ok(result));
        }