From 06eb5521dc25e732888a546aa6b57acf2f339100 Mon Sep 17 00:00:00 2001 From: n0099 Date: Mon, 16 Jan 2023 09:31:42 +0800 Subject: [PATCH] - method `RequestJsonForFirstPid()` due to https://github.com/Starry-OvO/aiotieba/issues/64#issuecomment-1383328421, partial revert commit 42b3c800cfe3eabca6dbb39ef313e716af7d3034 @ ThreadCrawler.cs * fix if the value of `ThreadPost.AgreeCount` is taken from `inPost.AgreeNum`, will not replace its value with zeros to NULL @ `ThreadParser.Convert()` @ crawler --- crawler/src/Tieba/Crawl/CrawlRequestFlag.cs | 3 +- .../src/Tieba/Crawl/Crawler/ThreadCrawler.cs | 37 +------------------ .../src/Tieba/Crawl/Parser/ThreadParser.cs | 7 +--- 3 files changed, 3 insertions(+), 44 deletions(-) diff --git a/crawler/src/Tieba/Crawl/CrawlRequestFlag.cs b/crawler/src/Tieba/Crawl/CrawlRequestFlag.cs index 884dae90..aacde9dd 100644 --- a/crawler/src/Tieba/Crawl/CrawlRequestFlag.cs +++ b/crawler/src/Tieba/Crawl/CrawlRequestFlag.cs @@ -4,7 +4,6 @@ public enum CrawlRequestFlag { None = 0, ThreadClientVersion602 = 1, - ThreadClientVersion8888 = 2, - ReplyShowOnlyFolded = 3 + ReplyShowOnlyFolded = 2 } } diff --git a/crawler/src/Tieba/Crawl/Crawler/ThreadCrawler.cs b/crawler/src/Tieba/Crawl/Crawler/ThreadCrawler.cs index 065407fa..16e32997 100644 --- a/crawler/src/Tieba/Crawl/Crawler/ThreadCrawler.cs +++ b/crawler/src/Tieba/Crawl/Crawler/ThreadCrawler.cs @@ -50,45 +50,10 @@ protected override Task> RequestsFactory(Page page) new Request(Requester.RequestProtoBuf(EndPointUrl, "6.0.2", new ThreadRequest {Data = data602}, (req, common) => req.Data.Common = common, - () => new ThreadResponse()), page, CrawlRequestFlag.ThreadClientVersion602), - new Request(RequestJsonForFirstPid(page), page, CrawlRequestFlag.ThreadClientVersion8888) + () => new ThreadResponse()), page, CrawlRequestFlag.ThreadClientVersion602) }.AsEnumerable()); } - private async Task RequestJsonForFirstPid(Page page) - { - var json = await Requester.RequestJson("c/f/frs/page", "8.8.8.8", new() - { - {"kw", _forumName}, - {"pn", page.ToString()}, - {"rn", "30"}, - {"sort_type", "5"} - }); - try - { - return new() - { - Error = new() {Errorno = 0}, - Data = new() - { - ThreadList = - { - json.GetProperty("thread_list").EnumerateArray().Select(el => new Thread - { - Tid = el.GetProperty("id").GetInt64(), - FirstPostId = el.GetProperty("first_post_id").GetInt64() - }) - } - } - }; - } - catch (Exception e) when (e is not TiebaException) - { - e.Data["raw"] = json; - throw; - } - } - public override IList GetValidPosts(ThreadResponse response, CrawlRequestFlag flag) { ValidateOtherErrorCode(response); diff --git a/crawler/src/Tieba/Crawl/Parser/ThreadParser.cs b/crawler/src/Tieba/Crawl/Parser/ThreadParser.cs index 4b6da9ac..b346da69 100644 --- a/crawler/src/Tieba/Crawl/Parser/ThreadParser.cs +++ b/crawler/src/Tieba/Crawl/Parser/ThreadParser.cs @@ -19,11 +19,6 @@ protected override bool ShouldSkipParse(CrawlRequestFlag requestFlag, IEnumerabl Helper.SerializedProtoBufOrNullIfEmpty(tuple.In.Location)); return true; }, - CrawlRequestFlag.ThreadClientVersion8888 => () => - { - joinedPosts.ForEach(tuple => tuple.Out.FirstReplyPid = (Pid)tuple.In.FirstPostId); - return true; - }, _ => throw new ArgumentOutOfRangeException( nameof(requestFlag), requestFlag, "Unexpected CrawlRequestFlag.") }; @@ -54,7 +49,7 @@ protected override ThreadPost Convert(Thread inPost) o.ViewCount = (uint?)inPost.ViewNum.NullIfZero(); o.ShareCount = (uint?)inPost.ShareNum.NullIfZero(); // when the thread is livepost, the agree field will not exists - o.AgreeCount = (int?)inPost.Agree?.AgreeNum.NullIfZero() ?? inPost.AgreeNum; + o.AgreeCount = (int?)inPost.Agree?.AgreeNum.NullIfZero() ?? inPost.AgreeNum.NullIfZero(); o.DisagreeCount = (int?)inPost.Agree?.DisagreeNum.NullIfZero(); o.Geolocation = Helper.SerializedProtoBufOrNullIfEmpty(inPost.Location); o.Zan = Helper.SerializedProtoBufOrNullIfEmpty(inPost.Zan);