Skip to content

Commit

Permalink
- method RequestJsonForFirstPid() due to lumina37/aiotieba#64 (comm…
Browse files Browse the repository at this point in the history
…ent), partial revert commit 42b3c80 @ 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
  • Loading branch information
n0099 committed Jan 16, 2023
1 parent affcf6a commit 06eb552
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 44 deletions.
3 changes: 1 addition & 2 deletions crawler/src/Tieba/Crawl/CrawlRequestFlag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public enum CrawlRequestFlag
{
None = 0,
ThreadClientVersion602 = 1,
ThreadClientVersion8888 = 2,
ReplyShowOnlyFolded = 3
ReplyShowOnlyFolded = 2
}
}
37 changes: 1 addition & 36 deletions crawler/src/Tieba/Crawl/Crawler/ThreadCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,45 +50,10 @@ protected override Task<IEnumerable<Request>> 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<ThreadResponse> 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<Thread> GetValidPosts(ThreadResponse response, CrawlRequestFlag flag)
{
ValidateOtherErrorCode(response);
Expand Down
7 changes: 1 addition & 6 deletions crawler/src/Tieba/Crawl/Parser/ThreadParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
};
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 06eb552

Please sign in to comment.