public static ForumPageMetadata Page(this ForumMetadata forum, int pageNumber) { ForumPageMetadata page = null; if (forum is UserBookmarksMetadata) { page = AwfulContentRequest.Forums.LoadUserBookmarks(); } else { page = AwfulContentRequest.Forums.LoadForumPage(forum.ForumID, pageNumber); } return(page); }
// TODO: Remember to sort thread data by new posts private static IList <ThreadMetadata> GenerateThreadData(ForumPageMetadata page, IEnumerable <HtmlNode> threadsInfo) { //Logger.AddEntry("AwfulForumPage - Generating thread data..."); List <ThreadMetadata> data = new List <ThreadMetadata>(); foreach (var node in threadsInfo) { var thread = ThreadParser.ParseThread(node); data.Add(thread); } return(data); }
private static void HandleMaxPages(ForumPageMetadata page, HtmlNode node) { var maxPagesNode = node.Descendants("div") .Where(n => n.GetAttributeValue("class", "").Equals("pages")) .FirstOrDefault(); if (maxPagesNode == null) { //Logger.AddEntry("AwfulForumPage - Could not parse maxPagesNode."); page.PageCount = 1; } else { page.PageCount = ExtractMaxForumPages(maxPagesNode); //Logger.AddEntry(string.Format("AwfulForumPage - maxPagesNode parsed. Value: {0}", page.Parent.TotalPages)); } }
public static ForumPageMetadata ParseForumPage(HtmlDocument doc) { var top = doc.DocumentNode; var page = new ForumPageMetadata(); int pageNumber = -1; // first, let's find the forum id var formNode = top.Descendants("form") .Where(node => node.GetAttributeValue("id", "").Equals("ac_timemachine")) .FirstOrDefault(); if (formNode != null) { string idString = formNode.GetAttributeValue("action", ""); // strip undesiriable stuff off idString = idString.Replace("/forumdisplay.php?", ""); idString = idString.Split('=').Last(); page.ForumID = idString; } // then, let's find the page number var pageNumberNode = top.Descendants("span") .Where(node => node.GetAttributeValue("class", "").Equals("curpage")) .FirstOrDefault(); if (pageNumberNode != null) { var pageNumberText = pageNumberNode.InnerText; if (!int.TryParse(pageNumberText, out pageNumber)) { pageNumber = -1; } } page.PageNumber = pageNumber; HandleMaxPages(page, top); HandleThreads(page, top); return(page); }
public static ForumPageMetadata Refresh(this ForumPageMetadata page) { return(AwfulContentRequest.Forums.LoadForumPage(page.ForumID, page.PageNumber)); }