提交 e5ebf68f 编辑于 作者: 刘 玉河's avatar 刘 玉河
浏览文件

feat: history

上级 455bb850
加载中
加载中
加载中
加载中

submit.py

100755 → 100644
+42 −4
原始行号 差异行号 差异行
@@ -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 or not submission_id:
        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()

@@ -109,17 +136,28 @@ if __name__ == "__main__":
            if not judge_time: 
                print("Submission %s is still in queue." % submission_id)
            else:
                if score < 0:
                    print("Submission %s for evaluation has failed. We are currently experiencing issues with the evaluation system. Please check official updates and try again later. This submission will not be counted into your quota." % submission_id)
                    exit(0)
                print("Submission %s score: %s" % (submission_id, score))
            exit(0)
        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)