Example #1
0
        private static IList <int> GetCloseVoteQueue(string mode)
        {
            var throttler = new RestRequestThrottler(SITE_URL, "tools", Method.GET, Authenticator);

            throttler.Request.AddHeader("X-Requested-With", "XMLHttpRequest");

            throttler.Request.AddParameter("tab", "close");
            throttler.Request.AddParameter("daterange", "today");
            throttler.Request.AddParameter("mode", mode);

            var response = throttler.Execute();

            var parser = new HtmlParser(response.Content);

            parser.Parse();

            var rows = parser.Result.QuerySelectorAll(".summary-table tr");

            return(rows.Select(r =>
            {
                var link = r.QuerySelector("td a");
                var url = link.GetAttribute("href");

                var match = QuestionIdRegex.Match(url);
                var id = int.Parse(match.Groups["questionID"].Value);

                return id;
            }).ToList());
        }
Example #2
0
        public static Dictionary <int, int> GetRecentCloseVoteReviews()
        {
            var throttler = new RestRequestThrottler(SITE_URL, "review/close/history", Method.GET, Authenticator);

            var response = throttler.Execute();
            var parser   = new HtmlParser(response.Content);

            var rows = parser.Result.QuerySelectorAll(".history-table tr");
            var dict = new Dictionary <int, int>();

            foreach (var row in rows)
            {
                var questionLinkElement = row.QuerySelector(".question-hyperlink");
                var reviewLinkElement   = row.QuerySelector("td:nth-child(3) a");

                var questionLinkHref = questionLinkElement.GetAttribute("href");
                var reviewLinkHref   = reviewLinkElement.GetAttribute("href");

                var questionMatch = QuestionIdRegex.Match(questionLinkHref);
                var reviewMatch   = ReviewIdRegex.Match(reviewLinkHref);
                if (questionMatch.Success && reviewMatch.Success)
                {
                    var questionId = int.Parse(questionMatch.Groups["questionID"].Value);
                    var reviewId   = int.Parse(reviewMatch.Groups["reviewID"].Value);

                    dict[questionId] = reviewId;
                }
            }
            return(dict);
        }
Example #3
0
        private IList <RestResponseCookie> GetAuthCookies()
        {
            lock (CookieLocker)
            {
                if (!CurrentAuthCookiesValid())
                {
                    var throttler = new RestRequestThrottler(BASE_URL, "users/login", Method.POST);
                    throttler.Client.FollowRedirects = false;

                    throttler.Request.AddParameter("email", _username);
                    throttler.Request.AddParameter("password", _password);

                    var response = throttler.Execute();
                    if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.Found)
                    {
                        throw new Exception("Failed to authenticate. Status recieved: " + response.StatusCode);
                    }

                    AuthCookies.AddRange(response.Cookies);
                    _refreshCookieTime = AuthCookies.Min(ac => ac.Expires);

                    AuthenticateSisterSites();
                }

                return(AuthCookies.ToList());
            }
        }