public static Question GetQuestion(ActiveQuestion activeQuestion) { var url = TrimUrl(activeQuestion.Url); var authorLink = TrimUrl(activeQuestion.OwnerUrl); var html = new WebClient().DownloadString(url); var dom = CQ.Create(html, Encoding.UTF8); var body = WebUtility.HtmlDecode(QuestionStatusDiv.Replace(dom[".post-text"].Html(), "").Trim()); var score = int.Parse(dom[".vote-count-post"].Html()); var creationDate = DateTime.MaxValue; foreach (var timestamp in dom[".post-signature .user-info .user-action-time .relativetime"]) { var dt = DateTime.Parse(timestamp.Attributes["title"]); if (dt < creationDate) creationDate = dt; } return new Question(activeQuestion.ID) { Url = url, Title = activeQuestion.TitleEncodedFancy, Body = body, Score = score, CreationDate = creationDate, AuthorName = activeQuestion.OwnerDisplayName, AuthorLink = authorLink, Tags = activeQuestion.Tags, Site = activeQuestion.SiteBaseHostAddress }; }
//private int ooooop = 0; /// <summary> /// Note that is *not* thread safe, and will be executing on separate threads /// </summary> private void HandleNewQuestion(ActiveQuestion activeQuestion) { //if (activeQuestion.SiteBaseHostAddress != "stackoverflow.com" || qIdCache.Any(x => x == activeQuestion.ID)) // return; //if (ooooop == 0) //{ // ooooop = 1; // var t = PostFetcher.GetQuestion("http://stackoverflow.com/questions/35381490"); // var t1 = SeApiAccessor.GetQuestion(35381490); //} //var question = PostFetcher.GetQuestion(activeQuestion); //while (qIdCache.Count > 1000) //{ // uint temp; // qIdCache.TryDequeue(out temp); //} //qIdCache.Enqueue(question.ID); //var sw = new Stopwatch(); //sw.Start(); //var res = qChecker.IsDupe(question, currentAlgo); //sw.Stop(); //Console.WriteLine($"Processed post {question.ID} in {sw.ElapsedMilliseconds}ms."); //if (res != null) //{ // var msg = new MessageBuilder(); // msg.AppendText($"Possible dupe ({Math.Round(res.MatchScore * 100)}%): "); // msg.AppendLink(question.Title, question.Url); // msg.AppendText($" of {res.LinkToDupeTarget}"); // chat.PostMessage(msg.ToString()); //} }
public override State Visit(ActiveQuestion state) { return(new States.ActiveQuestion(state.TargetPlayerName, state.Text)); }
public abstract T Visit(ActiveQuestion state);