diff --git a/tests/spider/csg_cpc/v1/csg_cpc_test.py b/tests/spider/csg_cpc/v1/csg_cpc_test.py index d8234d6..5c727b4 100644 --- a/tests/spider/csg_cpc/v1/csg_cpc_test.py +++ b/tests/spider/csg_cpc/v1/csg_cpc_test.py @@ -15,10 +15,11 @@ def test_spider_csg_cpc_v1_2023_hncpc(snapshot): fetch_uri = os.path.join(current_dir_path, "test_data/2023_hncpc") csg_cpc = CSG_CPC(c, fetch_uri) - csg_cpc.fetch().parse_teams().parse_runs() + csg_cpc.fetch().parse_teams().parse_runs().update_contest() assert len(csg_cpc.teams) == 180 assert len(csg_cpc.runs) == 2336 + snapshot.assert_match(csg_cpc.contest.get_json, "contest") snapshot.assert_match(csg_cpc.teams.get_json, "teams") snapshot.assert_match(csg_cpc.runs.get_json, "runs") diff --git a/tests/spider/csg_cpc/v1/snapshots/csg_cpc_test/test_spider_csg_cpc_v1_2023_hncpc/contest b/tests/spider/csg_cpc/v1/snapshots/csg_cpc_test/test_spider_csg_cpc_v1_2023_hncpc/contest new file mode 100644 index 0000000..1094ed4 --- /dev/null +++ b/tests/spider/csg_cpc/v1/snapshots/csg_cpc_test/test_spider_csg_cpc_v1_2023_hncpc/contest @@ -0,0 +1 @@ +{"contest_name": "", "start_time": "2023-11-11T15:30:00+08:00", "end_time": "2023-11-11T17:30:00+08:00", "frozen_time": 3600, "penalty": 1200, "problem_quantity": 0, "problem_id": [], "group": {"official": "\u6b63\u5f0f\u961f\u4f0d", "unofficial": "\u6253\u661f\u961f\u4f0d"}, "organization": "School", "status_time_display": {"correct": true, "incorrect": true, "pending": true}, "medal": {}, "options": {}} \ No newline at end of file diff --git a/tests/spider/csg_cpc/v1/test_data/2023_hncpc/contest.json b/tests/spider/csg_cpc/v1/test_data/2023_hncpc/contest.json new file mode 100644 index 0000000..0846ac3 --- /dev/null +++ b/tests/spider/csg_cpc/v1/test_data/2023_hncpc/contest.json @@ -0,0 +1,16 @@ +{ + "contest_id": 1001, + "title": "第九届中国大学生程序设计竞赛(深圳)- 热身赛", + "start_time": "2023-11-11 15:30:00", + "end_time": "2023-11-11 17:30:00", + "defunct": "0", + "description": "", + "private": 2, + "langmask": 75, + "password": "", + "attach": "2023-11-11_F0EA3F56319521FA", + "topteam": 1, + "award_ratio": 30020010, + "frozen_minute": 60, + "frozen_after": 0 +} diff --git a/xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py b/xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py index 91bc314..12bfced 100644 --- a/xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py +++ b/xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py @@ -14,6 +14,7 @@ def __init__(self, contest: Contest, self.raw_problem_data = [] self.raw_problem_map = {} + self.raw_contest_data = {} self.raw_team_data = [] self.raw_run_data = [] @@ -40,6 +41,9 @@ def fetch(self): raw_team_data = [] raw_run_data = [] + resp_obj = self.fetch_resp_obj(self.fetch_uri + "/contest.json") + self.raw_contest_data = resp_obj + resp_obj = self.fetch_resp_obj(self.fetch_uri + "/problem.json") raw_problem_data.extend(resp_obj) @@ -216,3 +220,12 @@ def parse_runs(self): self.runs = runs return self + + def update_contest(self): + start_time = self.raw_contest_data["start_time"] + end_time = self.raw_contest_data["end_time"] + frozen_minute = self.raw_contest_data["frozen_minute"] + + self.contest.start_time = start_time.replace(" ", "T") + "+08:00" + self.contest.end_time = end_time.replace(" ", "T") + "+08:00" + self.contest.frozen_time = int(frozen_minute) * 60