public ActionResult Index(bool update = false) { ViewBag.GetLatest = update; // specifies if we should show the update button List <FacebookSnapshot> latestSnapshots = new List <FacebookSnapshot>(); using (SportsDataContext db = new SportsDataContext()) { FacebookSnapshot latestSnapshot = (from d in db.FacebookSnapshot_DbSet orderby d.DateOfSnapshot descending select d).FirstOrDefault(); if (null != latestSnapshot) { DateTime latestDate = latestSnapshot.DateOfSnapshot; IEnumerable <FacebookSnapshot> results = from s in db.FacebookSnapshot_DbSet.Include(x => x.FacebookAccount) where DbFunctions.TruncateTime(s.DateOfSnapshot) == DbFunctions.TruncateTime(latestDate) //&& !s.FacebookAccountId.Equals("NhlToSeattle", StringComparison.InvariantCultureIgnoreCase) //&& !s.FacebookAccountId.Equals("Nhl", StringComparison.InvariantCultureIgnoreCase) orderby s.FacebookAccount.FriendlyName select s; latestSnapshots = results.ToList(); } } return(Result(latestSnapshots)); }
public void FacebookGetSnapshot() { FacebookAccount account = new FacebookAccount { Id = "NHLBruins", FriendlyName = "Boston Bruins" }; FacebookSnapshot accountSnapshot = FacebookQuery.GetFacebookSnapshot(account); Assert.AreEqual(DateTime.UtcNow.Date, accountSnapshot.DateOfSnapshot.Date, "The snapshot is from today"); Assert.IsTrue(accountSnapshot.TotalLikes > 0, "There are more than 0 likes"); Assert.IsTrue(accountSnapshot.PeopleTalkingAboutThis > 0, "There are more than 0 people talking about this"); Assert.IsTrue(accountSnapshot.MostPopularWeek > DateTime.MinValue, "The most popular week is not the default DateTime.MinValue"); Assert.AreNotEqual(String.Empty, accountSnapshot.MostPopularCity, "The most popular city is not empty"); Assert.AreNotEqual(String.Empty, accountSnapshot.MostPopularAgeGroup, "The most popular age group is not empty"); Assert.AreEqual(account.Id, accountSnapshot.FacebookAccountId, "There account name is correct in the snapshot"); Assert.AreEqual("NHLBruins", accountSnapshot.FacebookAccountId, "There account name is NHLBruins"); }
protected override SocialBaseSnapshot ParsePage(HtmlNode documentNode, SocialBaseAccount account) { FacebookSnapshot accountSnapshot = new FacebookSnapshot(); accountSnapshot.FacebookAccountId = account.Id; if (null == documentNode) { return(null); } // We need to strip out comment tags. Facebook puts the this data in comment tags and HAP does not parse through comments. documentNode.InnerHtml = documentNode.InnerHtml.Replace("<!--", String.Empty).Replace("-->", String.Empty); string totalLikesXPath = @"//h3[text() = 'Total Likes']/../../../../div/span[@class='timelineLikesBigNumber fsm']"; HtmlNode totalLikes = documentNode.SelectSingleNode(totalLikesXPath); HtmlNodeCollection likes = documentNode.SelectNodes(totalLikesXPath); if (null == totalLikes) { accountSnapshot.TotalLikes = -1; accountSnapshot.Log += "Could not find totalLikes using " + totalLikesXPath + Environment.NewLine; } else { accountSnapshot.TotalLikes = int.Parse(totalLikes.InnerText, NumberStyles.AllowThousands); } string peopleTalkingAboutThisXPath = @"//h3[text() = 'People Talking About This']/../../../../div/span[@class='timelineLikesBigNumber fsm']"; HtmlNode peopleTalkingAboutThis = documentNode.SelectSingleNode(peopleTalkingAboutThisXPath); if (null == peopleTalkingAboutThis) { accountSnapshot.PeopleTalkingAboutThis = -1; accountSnapshot.Log += "Could not find peopleTalkingAboutThis using " + peopleTalkingAboutThisXPath + Environment.NewLine; } else { accountSnapshot.PeopleTalkingAboutThis = int.Parse(peopleTalkingAboutThis.InnerText, NumberStyles.AllowThousands); } string mostPopularWeekXPath = @"//span[text()='Most Popular Week']"; HtmlNode mostPopularWeek = documentNode.SelectSingleNode(mostPopularWeekXPath); if (null != mostPopularWeek && null != mostPopularWeek.PreviousSibling) { accountSnapshot.MostPopularWeek = DateTime.Parse(mostPopularWeek.PreviousSibling.InnerText); } else { accountSnapshot.MostPopularWeek = new DateTime(1900, 1, 1); accountSnapshot.Log += "Could not find mostPopularWeek using " + mostPopularWeekXPath + Environment.NewLine; } string mostPopularCityXPath = @"//span[text()='Most Popular City']"; HtmlNode mostPopularCity = documentNode.SelectSingleNode(mostPopularCityXPath); if (null != mostPopularCity && null != mostPopularCity.PreviousSibling) { accountSnapshot.MostPopularCity = mostPopularCity.PreviousSibling.InnerText; } else { accountSnapshot.MostPopularCity = String.Empty; accountSnapshot.Log += "Could not find mostPopularCity using " + mostPopularCityXPath + Environment.NewLine; } string mostPopularAgeGroupXPath = @"//span[text()='Most Popular Age Group']"; HtmlNode mostPopularAgeGroup = documentNode.SelectSingleNode(mostPopularAgeGroupXPath); if (null != mostPopularAgeGroup && null != mostPopularAgeGroup.PreviousSibling) { accountSnapshot.MostPopularAgeGroup = mostPopularAgeGroup.PreviousSibling.InnerText; } else { accountSnapshot.MostPopularAgeGroup = String.Empty; accountSnapshot.Log += "Could not find mostPopularAgeGroup using " + mostPopularAgeGroupXPath + Environment.NewLine; } return(accountSnapshot); }