From 08be61ca47ca237d556301c7307b2556704a877c Mon Sep 17 00:00:00 2001 From: Dup4 Date: Sun, 12 Nov 2023 01:27:56 +0800 Subject: [PATCH 1/2] feat: update time for csg Signed-off-by: Dup4 --- tests/spider/csg_cpc/v1/csg_cpc_test.py | 1 + .../test_spider_csg_cpc_v1_2023_hncpc/contest | 1 + .../csg_cpc/v1/test_data/2023_hncpc/contest.json | 16 ++++++++++++++++ xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py | 13 +++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 tests/spider/csg_cpc/v1/snapshots/csg_cpc_test/test_spider_csg_cpc_v1_2023_hncpc/contest create mode 100644 tests/spider/csg_cpc/v1/test_data/2023_hncpc/contest.json diff --git a/tests/spider/csg_cpc/v1/csg_cpc_test.py b/tests/spider/csg_cpc/v1/csg_cpc_test.py index d8234d6..dead13a 100644 --- a/tests/spider/csg_cpc/v1/csg_cpc_test.py +++ b/tests/spider/csg_cpc/v1/csg_cpc_test.py @@ -20,5 +20,6 @@ def test_spider_csg_cpc_v1_2023_hncpc(snapshot): 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..fd591d1 --- /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": 1694912400, "end_time": 1694930400, "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..da32007 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 = utils.get_timestamp_second(start_time) + self.contest.end_time = utils.get_timestamp_second(end_time) + self.contest.frozen_time = int(frozen_minute) * 60 From 8dbb3e071f3d45b006223f4d36acd95f4d0b04ca Mon Sep 17 00:00:00 2001 From: Dup4 Date: Sun, 12 Nov 2023 01:32:51 +0800 Subject: [PATCH 2/2] fix: add timezone Signed-off-by: Dup4 --- tests/spider/csg_cpc/v1/csg_cpc_test.py | 2 +- .../csg_cpc_test/test_spider_csg_cpc_v1_2023_hncpc/contest | 2 +- xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/spider/csg_cpc/v1/csg_cpc_test.py b/tests/spider/csg_cpc/v1/csg_cpc_test.py index dead13a..5c727b4 100644 --- a/tests/spider/csg_cpc/v1/csg_cpc_test.py +++ b/tests/spider/csg_cpc/v1/csg_cpc_test.py @@ -15,7 +15,7 @@ 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 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 index fd591d1..1094ed4 100644 --- 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 @@ -1 +1 @@ -{"contest_name": "", "start_time": 1694912400, "end_time": 1694930400, "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 +{"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/xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py b/xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py index da32007..12bfced 100644 --- a/xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py +++ b/xcpcio_board_spider/spider/csg_cpc/v1/csg_cpc.py @@ -226,6 +226,6 @@ def update_contest(self): end_time = self.raw_contest_data["end_time"] frozen_minute = self.raw_contest_data["frozen_minute"] - self.contest.start_time = utils.get_timestamp_second(start_time) - self.contest.end_time = utils.get_timestamp_second(end_time) + 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