Example #1
0
        public ActionResult Index(bool update = false)
        {
            ViewBag.GetLatest = update; // specifies if we should show the update button

            List <TwitterSnapshot> latestSnapshots = new List <TwitterSnapshot>();

            using (SportsDataContext db = new SportsDataContext())
            {
                TwitterSnapshot latestSnapshot = (from d in db.TwitterSnapshot_DbSet
                                                  orderby d.DateOfSnapshot descending
                                                  select d).FirstOrDefault();

                if (null != latestSnapshot)
                {
                    DateTime latestDate = latestSnapshot.DateOfSnapshot;

                    IEnumerable <TwitterSnapshot> results = from s in db.TwitterSnapshot_DbSet.Include(x => x.TwitterAccount)
                                                            where DbFunctions.TruncateTime(s.DateOfSnapshot) == DbFunctions.TruncateTime(latestDate)
                                                            //&& !s.TwitterAccountId.Equals("NhlToSeattle", StringComparison.InvariantCultureIgnoreCase)
                                                            //&& !s.TwitterAccountId.Equals("Nhl", StringComparison.InvariantCultureIgnoreCase)
                                                            orderby s.TwitterAccount.FriendlyName
                                                            select s;

                    latestSnapshots = results.ToList();
                }
            }

            return(Result(latestSnapshots));
        }
Example #2
0
        protected override SocialBaseSnapshot ParsePage(HtmlNode documentNode, SocialBaseAccount account)
        {
            TwitterSnapshot twitterAccountSnapshot = new TwitterSnapshot();

            twitterAccountSnapshot.TwitterAccountId = account.Id;

            if (null == documentNode)
            {
                return(null);
            }

            string   tweetCountXPath = @"//a[@data-element-term='tweet_stats']/strong";
            HtmlNode tweetCount      = documentNode.SelectSingleNode(tweetCountXPath);

            if (null == tweetCount)
            {
                twitterAccountSnapshot.Tweets = -1;
                twitterAccountSnapshot.Log   += "Could not find tweetCount using " + tweetCountXPath + Environment.NewLine;
            }
            else
            {
                twitterAccountSnapshot.Tweets = int.Parse(tweetCount.InnerText, NumberStyles.AllowThousands);
            }

            string   followingCountXPath = @"//a[@data-element-term='following_stats']/strong";
            HtmlNode followingCount      = documentNode.SelectSingleNode(followingCountXPath);

            if (null == followingCount)
            {
                twitterAccountSnapshot.Following = -1;
                twitterAccountSnapshot.Log      += "Could not find followingCount using " + followingCountXPath + Environment.NewLine;
            }
            else
            {
                twitterAccountSnapshot.Following = int.Parse(followingCount.InnerText, NumberStyles.AllowThousands);
            }


            string   followerCountXPath = @"//a[@data-element-term='follower_stats']/strong";
            HtmlNode followerCount      = documentNode.SelectSingleNode(followerCountXPath);

            if (null == followerCount)
            {
                twitterAccountSnapshot.Followers = -1;
                twitterAccountSnapshot.Log      += "Could not find followerCount using " + followerCountXPath + Environment.NewLine;
            }
            else
            {
                twitterAccountSnapshot.Followers = int.Parse(followerCount.InnerText, NumberStyles.AllowThousands);
            }

            return(twitterAccountSnapshot);
        }
Example #3
0
        public void TwitterGetSnapshot()
        {
            TwitterAccount twitterAccount = new TwitterAccount {
                Id = "sanjosesharks", FriendlyName = "San Jose Sharks"
            };
            TwitterSnapshot twitterAccountSnapshot = TwitterQuery.GetTwitterSnapshot(twitterAccount);

            Assert.AreEqual(DateTime.UtcNow.Date, twitterAccountSnapshot.DateOfSnapshot.Date, "The snapshot is from today");
            Assert.IsTrue(twitterAccountSnapshot.Tweets > 0, "There are more than 0 tweets");
            Assert.IsTrue(twitterAccountSnapshot.Following > 0, "There are more than 0 following");
            Assert.IsTrue(twitterAccountSnapshot.Followers > 0, "There are more than 0 followers");
            Assert.AreEqual(twitterAccount.Id, twitterAccountSnapshot.TwitterAccountId, "There account name is correct in the snapshot");

            Assert.AreEqual("sanjosesharks", twitterAccountSnapshot.TwitterAccountId, "There account name is sanjosesharks");
        }