/// <summary> /// Retrieves all subscribed <c>SectionThread</c>s using the logged-in user account /// </summary> /// <param name="session">Session used for sending the request</param> /// <returns> List of all subscribed <c>SectionThread</c>s that could be retrieved </returns> public List <SectionThread> GetSubscribedThreads(AuthenticatedSession <TUser> session) { session.ThrowIfInvalid(); var subscribedThreads = new List <SectionThread>(); var res = session.Get("http://www.elitepvpers.com/forum/subscription.php?do=viewsubscription&daysprune=-1&folderid=all"); var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(res); // a bit ugly but it works so far var rootNode = htmlDocument.DocumentNode.SelectSingleNode("//tr/td[@class='tcat']/span[@class='smallfont']").ParentNode.ParentNode.ParentNode; if (rootNode == null) { return(null); } foreach (var node in rootNode.ChildNodes.GetElementsByName("tr")) { if (node.SelectSingleNode("td[@class='thead']") != null || node.SelectSingleNode("td[@class='tcat']") != null || node.SelectSingleNode("td[@class='tfoot']") != null) { continue; } var threadId = new Regex("<td class=\"alt1\" id=\"td_threadtitle_(.*?)\"").Match(node.InnerHtml).Groups[1].Value.To <int>(); var threadSection = new Regex("<a href=\"(.*?)/.*?\" id=\"thread_title_.*?\">.*?</a>").Match(node.InnerHtml).Groups[1].Value; var section = Section.Sections.FirstOrDefault(n => n.Shortname == threadSection); var subscribedThread = new SectionThread(threadId, section); subscribedThreads.Add(subscribedThread); } return(subscribedThreads); }
public SectionPost(int id, SectionThread thread, Content content, string title = null) : base(id, content, title) { Thread = thread; }
public SectionPost(int id, SectionThread thread, string title = null) : this(id, thread, new Content(), title) { Thread = thread; }
/// <summary> /// Loops through the section pages and retrieves the <c>SectionThread</c>s within this section /// </summary> /// <param name="session"> Session that is used for sending the request </param> /// <param name="pages"> Amount of pages to request </param> /// <param name="startIndex"> Index of the first page that will be requested </param> /// <returns> List of all <c>SectionThread</c>s that could be obtained through the requests </returns> public List <SectionThread> Threads <TUser>(AuthenticatedSession <TUser> session, uint pages = 1, uint startIndex = 1) where TUser : User { session.ThrowIfInvalid(); if (Shortname == String.Empty) { throw new ArgumentException("This section is not addressable, please specify the URLName property before using this function"); } var parsedThreads = new List <SectionThread>(); for (uint i = startIndex; i < startIndex + pages; ++i) { var res = session.Get(String.Format("https://www.elitepvpers.com/forum/{0}/index{1}.html", Shortname, i)); var doc = new HtmlDocument(); doc.LoadHtml(res); var threadFrameNode = doc.GetElementbyId("threadbits_forum_" + ID); if (threadFrameNode == null) { continue; } var threadNodes = new List <HtmlNode>(threadFrameNode.ChildNodes.GetElementsByTagName("tr")); var normalThreadsBeginNode = threadNodes.Find(node => ((node.SelectSingleNode("td[1]") != null) ? node.SelectSingleNode("td[1]").InnerText : "") == "Normal Threads"); var stickyThreadsBeginNode = threadNodes.Find(node => ((node.SelectSingleNode("td[1]/strong[1]") != null) ? node.SelectSingleNode("td[1]/strong[1]").InnerText : "") == "Sticky Threads"); var normalThreadNodes = new List <HtmlNode>(); var stickyThreadNodes = new List <HtmlNode>(); var totalThreadNodes = new List <HtmlNode>(); if (stickyThreadsBeginNode != null && normalThreadsBeginNode != null) // if there are any sticky threads present { // extract the productive threads into their own sublists, ignore the leading identifiers (= +1) that are displayed as section divider ('Sticky Threads', 'Normal Threads' ...) stickyThreadNodes = threadNodes.GetRange(threadNodes.IndexOf(stickyThreadsBeginNode) + 1, threadNodes.IndexOf(normalThreadsBeginNode) - threadNodes.IndexOf(stickyThreadsBeginNode) - 1); normalThreadNodes = threadNodes.GetRange(threadNodes.IndexOf(normalThreadsBeginNode) + 1, threadNodes.Count - stickyThreadNodes.Count - 2); // -2 since we have 2 dividers totalThreadNodes.InsertRange(totalThreadNodes.Count, normalThreadNodes); totalThreadNodes.InsertRange((totalThreadNodes.Count != 0) ? totalThreadNodes.Count - 1 : 0, stickyThreadNodes); } else { totalThreadNodes = threadNodes; } foreach (var threadNode in totalThreadNodes) { // skip deleted threads, since we can't parse them (yet) if (threadNode.SelectSingleNode("td[6]") == null) { continue; } var parsedThread = new SectionThread(0, this); new SectionParser.ThreadListingParser(parsedThread).Execute(threadNode); if (stickyThreadNodes.Any(stickyThreadNode => stickyThreadNode == threadNode)) { parsedThread.Sticked = true; } if (parsedThread.ID != 0) { parsedThreads.Add(parsedThread); } } } return(parsedThreads); }