You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 rivejä
4.4 KiB

3 vuotta sitten
  1. import requests
  2. import re
  3. import time
  4. def submit(payload) :
  5. url = "http://jf.shuishan.net.cn/api/submission"
  6. payload = payload
  7. headers = {
  8. 'Host': 'jf.shuishan.net.cn',
  9. 'Connection': 'keep-alive',
  10. 'Content-Length': '101',
  11. 'Accept': 'application/json, text/plain, */*',
  12. 'X-CSRFToken': '6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6',
  13. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
  14. 'Chrome/88.0.4324.104 Safari/537.36',
  15. 'Content-Type': 'application/json;charset=UTF-8',
  16. 'Origin': 'http://jf.shuishan.net.cn',
  17. 'Referer': 'http://jf.shuishan.net.cn/problem/1-1',
  18. 'Accept-Encoding': 'gzip, deflate',
  19. 'Accept-Language': 'zh-CN,zh;q=0.9',
  20. 'Cookie': '_ga=GA1.3.1580759526.1611565238; _gid=GA1.3.412268444.1611565238; csrftoken=6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml; _gat=1; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml'
  21. }
  22. response = requests.request("POST", url, headers=headers, data=payload)
  23. ## print(response.text)
  24. res = response.text
  25. submit_id = re.findall(r'"submission_id": "([^"]+)"',res)
  26. submit_id = submit_id[0]
  27. with open('submit_id.txt', 'w', encoding='utf-8', newline='') as f: # 设置文件对象
  28. f.write(submit_id) # 将字符串写入文件中
  29. f.close()
  30. ## print(submit_id)
  31. #获取judge信息
  32. url = "http://jf.shuishan.net.cn/api/submission?id="+str(submit_id)
  33. #url = "http://jf.shuishan.net.cn/api/submission?id=2610feac243108d927e8760f24b808c6"
  34. payload={}
  35. headers = {
  36. 'Host': 'jf.shuishan.net.cn',
  37. 'Connection': 'keep-alive',
  38. 'Accept': 'application/json, text/plain, */*',
  39. 'X-CSRFToken': '6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6',
  40. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36',
  41. 'Content-Type': 'application/json;charset=utf-8',
  42. 'Referer': 'http://jf.shuishan.net.cn/problem/1-1',
  43. 'Accept-Encoding': 'gzip, deflate',
  44. 'Accept-Language': 'zh-CN,zh;q=0.9',
  45. 'Cookie': '_ga=GA1.3.1580759526.1611565238; _gid=GA1.3.412268444.1611565238; csrftoken=6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml; _gat=1; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml'
  46. }
  47. #等待judgeserver出结果
  48. time.sleep(0.5)
  49. response = requests.request("GET", url, headers=headers, data=payload)
  50. print(response.text)
  51. res = response.text
  52. result_code = re.findall(r'"result": ([^"]+),',res)
  53. error_code = re.findall(r'"error": ([^"]+),',res)
  54. result_code = result_code[1]
  55. error_code = error_code[0]
  56. print(result_code)
  57. print(error_code)
  58. if(error_code != '0' and error_code != "null"):
  59. print("ERROR_CODE")
  60. return "ERROR_CODE"
  61. elif(result_code == '0'):
  62. print("SUCCESS")
  63. return "SUCCESS"
  64. elif(result_code == '1'):
  65. print("CPU_TIME_LIMIT_EXCEEDED")
  66. return "CPU_TIME_LIMIT_EXCEEDED"
  67. elif(result_code == '2'):
  68. print("REAL_TIME_LIMIT_EXCEEDED")
  69. return "REAL_TIME_LIMIT_EXCEEDED"
  70. elif(result_code == '3'):
  71. print("MEMORY_LIMIT_EXCEEDED")
  72. return "MEMORY_LIMIT_EXCEEDED"
  73. elif(result_code == '4'):
  74. print("RUNTIME_ERROR")
  75. return "RUNTIME_ERROR"
  76. elif (result_code == '5'):
  77. print("SYSTEM_ERROR")
  78. return "SYSTEM_ERROR"
  79. else:
  80. print("WRONG_ANSWER")
  81. return "WRONG_ANSWER"
  82. #写入一个输出文件
  83. def submit_handler(code, problem_id, language_type):
  84. with open('data.c', 'w', encoding='utf-8', newline='') as f:
  85. f.write(code)
  86. f.close()
  87. file = open('data.c', mode='r', encoding='utf-8', newline='')
  88. code = file.readlines()
  89. file.close()
  90. code = ''.join([i.replace(' ', r'\t').replace('"', r'\"').rstrip() + r'\n' for i in code])
  91. ## print(code)
  92. # payload="{\"problem_id\":1,\"language\":\"C\",\"code\":\"# include <stdio.h>\\nint main()\\n{\\n\\tint a;\\n\\treturn 0;\\n}\"}"
  93. # print(payload)
  94. payload = "{\"problem_id\":" + problem_id + ",\"language\":\"" + language_type + "\",\"code\":\"" + code + "\"}"
  95. ## print(payload)
  96. results = submit(payload)
  97. return results
  98. # 输入文件名,题号,语言种类
  99. #results = submit_handler('22.c','22','C')
  100. #print(results)
  101. #获取逻辑错误信息