diff --git a/README.md b/README.md index 242489a3a14340f0c80c68cdd1003aaab48db83e..d780d31ba59ec0902bce33c7bcb8da531334ab8c 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ python submit.py [-h] [-s SERVER] [-c CONTEST] [-k TICKET] [-i SUBMISSION_ID] [r * `-c, --contest`:比赛标识。如果未提供,将使用脚本中定义的 `CONTEST` 变量。 * `-k, --ticket`:团队标识。如果未提供,将使用脚本中定义的 `TICKET` 变量。 * `-i, --submission_id` :提交ID,当指定这一参数时,该脚本将不会提交结果文件,而是会查询该提交ID的结果。 +* `-H, --history`:查询历史提交记录,当指定这一参数时,该脚本将不会提交结果文件,而是会查询给定赛道和团队的历史提交评测结果。 ## 单次提交结果查询 @@ -36,6 +37,14 @@ python submit.py -i -s -c -k 由于评测服务器可能需要一段时间来处理提交,因此您可能需要等待一段时间才能获得结果。 +## 历史提交结果查询 + +示例: + +```bash +python submit.py -H -s -c -k +``` + ## 编程方式提交 您还可以将 `submit` 函数导入到您的 Python 代码中,以便用编程方式提交数据。 diff --git a/submit.py b/submit.py old mode 100755 new mode 100644 index 0daebbd9c259de50b312540c93e2efdfc8467bc3..df8179edd8ee4c8316ad404e7ca57296177a6ead --- a/submit.py +++ b/submit.py @@ -51,6 +51,32 @@ def submit(data, judge_server=None, contest=None, ticket=None): print(e.reason) return None +def get_history(judge_server=None, contest=None, ticket=None): + judge_server = judge_server or JUDGE_SERVER + contest = contest or CONTEST + ticket = ticket or TICKET + + if not judge_server or not contest or not ticket: + missing = [ + "judge_server" if not judge_server else "", + "contest" if not contest else "", + "ticket" if not ticket else "", + ] + missing = [m for m in missing if m] + print("Required fields must be provided: %s" % ', '.join(missing)) + return None + + req = request.Request(judge_server + "/history/", headers={'ticket': ticket, 'contest': contest, 'Content-Type': 'application/json'}) + + try: + with request.urlopen(req) as response: + response_body = response.read().decode('utf-8') + history = json.loads(response_body) + return history + except: + print("Failed to get submission history.") + return None + def check_status(submission_id, judge_server=None, contest=None, ticket=None): judge_server = judge_server or JUDGE_SERVER contest = contest or CONTEST @@ -95,6 +121,7 @@ if __name__ == "__main__": parser.add_argument('-c', '--contest', help='Contest ID, if not specified, the global CONTEST variable will be used') parser.add_argument('-k', '--ticket', help='Submission ticket, if not specified, the global TICKET variable will be used') parser.add_argument('-i', '--submission_id', help='Submission ID, specified if you want to check the submission status', default=None) + parser.add_argument('-H', '--history', help='Get submission history', action='store_true') args = parser.parse_args() @@ -117,9 +144,23 @@ if __name__ == "__main__": else: print("Failed to check submission status.") exit(1) + elif args.history: + history = get_history(judge_server=args.server, contest=args.contest, ticket=args.ticket) + if history: + print("="*16) + for submission in history: + print(f"Submission {submission['submission_id']}:") + print(f" - Create time: {submission['create_time']}") + print(f" - Judge time: {submission['judge_time']}") + print(f" - Score: {submission['score']}") + print("="*16) + exit(0) + else: + print("Failed to get submission history.") + exit(1) try: - with open(args.result_path, 'r') as file: + with open(args.result_path, 'r', encoding='utf-8') as file: data = [json.loads(line.strip()) for line in file if line.strip()] except Exception as e: print(e)