示例#1
0
        /// <summary>
        /// Gets the next TweetSummary from the queue.
        /// </summary>
        /// <returns></returns>
        public static TweetSummary GetNext()
        {
            TweetSummary ts = null;

            tweetQueue.TryDequeue(out ts);
            return(ts);
        }
示例#2
0
        public static TweetSummary GetTweetSummary(string CompanyName, TraceWriter log)
        {
            TweetSummary result = new TweetSummary()
            {
                CompanyName = CompanyName
            };

            List <Tweet> tweets = ServiceProxies.SearchTweets(CompanyName);

            log.Info($"Found {tweets.Count.ToString()} tweets for company {CompanyName}");
            foreach (Tweet tweet in tweets)
            {
                DateTime publishDateTime = DateTime.ParseExact(tweet.DatePublished, "ddd MMM dd HH:mm:ss zzz yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeLocal);

                // Set Start and End dates, if appropriate
                if (result.StartDate == DateTime.MinValue || publishDateTime < result.StartDate)
                {
                    result.StartDate = publishDateTime;
                }
                if (result.EndDate == DateTime.MinValue || publishDateTime > result.EndDate)
                {
                    result.EndDate = publishDateTime;
                }

                if (result.Tweets.ContainsKey(tweet.Id))
                {
                    if (tweet.RetweetCount > result.Tweets[tweet.Id].RetweetCount)
                    {
                        result.Tweets[tweet.Id].RetweetCount = tweet.RetweetCount;
                    }
                    if (tweet.FavoriteCount > result.Tweets[tweet.Id].FavoriteCount)
                    {
                        result.Tweets[tweet.Id].FavoriteCount = tweet.FavoriteCount;
                    }
                }
                else
                {
                    result.Tweets.Add(tweet.Id, tweet);
                }
            }

            result.TweetCount = result.Tweets.Count;

            foreach (Tweet tweet in result.Tweets.Values)
            {
                result.TweetLikes    += tweet.FavoriteCount;
                result.TweetRetweets += tweet.RetweetCount;
            }

            return(result);
        }
        public static string Update(TraceWriter log)
        {
            string result = "Daily update complete, nothing unusual to report..";

            try
            {
                List <Company> companies = Utils.DataRepository.GetCompaniesFromDb(log);

                foreach (Company company in companies)
                {
                    if (!String.IsNullOrEmpty(company.Symbol))
                    {
                        DailyUpdate update = new DailyUpdate()
                        {
                            Name = company.Name, Symbol = company.Symbol, Date = DateTime.Now
                        };
                        //update.Id = company.Name + "_" + update.Date.ToString("yyyyMMdd");
                        //update.Id = update.Id.Replace(" ", "_");

                        TweetSummary tweets = TwitterUtils.GetTweetSummary(company.Name, log);
                        update.TweetCount    = tweets.TweetCount;
                        update.TweetLikes    = tweets.TweetLikes;
                        update.TweetRetweets = tweets.TweetRetweets;
                        update.StockPrice    = ServiceProxies.GetStockPrice(company.Symbol, "", log);
                        GitHub ghub = ServiceProxies.GetGitHubStars(company.Name);
                        if (ghub != null)
                        {
                            update.GitHubStars    = ghub.Stars;
                            update.GitHubWatchers = ghub.Watches;
                        }

                        List <News> news = ServiceProxies.SearchNews(company.Name, log);
                        update.NewsStories = news.Count;

                        DataRepository.AddDailyUpdate(update);

                        // Sleep to not overload free APIs
                        System.Threading.Thread.Sleep(12000);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                result = "DailyUpdater Error: " + ex.ToString();
            }

            return(result);
        }
示例#4
0
 public ItemAddedArgs(TweetSummary tweetSummary)
 {
     ItemAdded = tweetSummary;
 }
示例#5
0
 /// <summary>
 /// Adds a new TweetSummary to the queue.
 /// </summary>
 /// <param name="tweetSummary"></param>
 public static void Add(TweetSummary tweetSummary)
 {
     tweetQueue.Enqueue(tweetSummary);
     ItemAdded?.Invoke(null, new ItemAddedArgs(tweetSummary));
 }
 /// <summary>
 /// Returns a copy of the data, rather than a reference to the same list.
 /// </summary>
 /// <returns></returns>
 public static List <TweetSummary> GetData()
 {
     TweetSummary[] copy = new TweetSummary[allTweets.Count];
     allTweets.CopyTo(copy, 0);;
     return(new List <TweetSummary>(copy));
 }