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.

155 lines
5.3 KiB

  1. import requests
  2. import re
  3. import time
  4. def submit(payload,pid) :
  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-'+pid,
  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.encode('utf-8').decode('latin1'))
  23. ## print(response.text)
  24. res = response.text
  25. with open('wulin3.txt', 'w', encoding='utf-8', newline='') as f:
  26. f.write(res)
  27. f.close()
  28. submit_id = re.findall(r'"submission_id": "([^"]+)"',res)
  29. submit_id = submit_id[0]
  30. with open('submit_id.txt', 'w', encoding='utf-8', newline='') as f: # 设置文件对象
  31. f.write(submit_id) # 将字符串写入文件中
  32. f.close()
  33. ## print(submit_id)
  34. #获取judge信息
  35. url = "http://jf.shuishan.net.cn/api/submission?id="+str(submit_id)
  36. #url = "http://jf.shuishan.net.cn/api/submission?id=2610feac243108d927e8760f24b808c6"
  37. payload={}
  38. headers = {
  39. 'Host': 'jf.shuishan.net.cn',
  40. 'Connection': 'keep-alive',
  41. 'Accept': 'application/json, text/plain, */*',
  42. 'X-CSRFToken': '6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6',
  43. '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',
  44. 'Content-Type': 'application/json;charset=utf-8',
  45. 'Referer': 'http://jf.shuishan.net.cn/problem/1-'+pid,
  46. 'Accept-Encoding': 'gzip, deflate',
  47. 'Accept-Language': 'zh-CN,zh;q=0.9',
  48. 'Cookie': '_ga=GA1.3.1580759526.1611565238; _gid=GA1.3.412268444.1611565238; csrftoken=6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml; _gat=1; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml'
  49. }
  50. #等待judgeserver出结果
  51. time.sleep(0.5)
  52. response = requests.request("GET", url, headers=headers, data=payload)
  53. # print(response.text)
  54. res = response.text
  55. with open('wulin5.txt', 'w', encoding='utf-8', newline='') as f:
  56. f.write(res)
  57. f.close()
  58. result_code = re.findall(r'"result": ([^"]+),',res)
  59. error_code = re.findall(r'"error": ([^"]+),',res)
  60. result_code_compile = result_code[0]
  61. if (len(result_code) >= 2) :
  62. result_code = result_code[1]
  63. error_code = error_code[0]
  64. print(result_code)
  65. print(error_code)
  66. if(error_code != '0' and error_code != "null"):
  67. print("ERROR_CODE")
  68. return "ERROR_CODE"
  69. if (result_code_compile == '-2') :
  70. print("COMPILE_ERROR")
  71. return "COMPILE_ERROR"
  72. if(error_code != '0' and error_code != "null"):
  73. print("ERROR_CODE")
  74. return "ERROR_CODE"
  75. elif(result_code == '0'):
  76. print("SUCCESS")
  77. return "SUCCESS"
  78. elif(result_code == '1'):
  79. print("CPU_TIME_LIMIT_EXCEEDED")
  80. return "CPU_TIME_LIMIT_EXCEEDED"
  81. elif(result_code == '2'):
  82. print("REAL_TIME_LIMIT_EXCEEDED")
  83. return "REAL_TIME_LIMIT_EXCEEDED"
  84. elif(result_code == '3'):
  85. print("MEMORY_LIMIT_EXCEEDED")
  86. return "MEMORY_LIMIT_EXCEEDED"
  87. elif(result_code == '4'):
  88. print("RUNTIME_ERROR")
  89. return "RUNTIME_ERROR"
  90. elif (result_code == '5'):
  91. print("SYSTEM_ERROR")
  92. return "SYSTEM_ERROR"
  93. else:
  94. print("WRONG_ANSWER")
  95. return "WRONG_ANSWER"
  96. #写入一个输出文件
  97. def submit_handler(code, problem_id, language_type):
  98. with open('data.c', 'w', encoding='utf-8', newline='') as f:
  99. f.write(code)
  100. f.close()
  101. file = open('data.c', mode='r', encoding='utf-8', newline='')
  102. code = file.readlines()
  103. file.close()
  104. code = ''.join([i.replace("\t"," ").replace('\\', '\\\\').replace('"', r'\"').rstrip() + r'\n' for i in code])
  105. ## print(code)
  106. # payload="{\"problem_id\":1,\"language\":\"C\",\"code\":\"# include <stdio.h>\\nint main()\\n{\\n\\tint a;\\n\\treturn 0;\\n}\"}"
  107. # print(payload)
  108. payload = "{\"problem_id\":" + problem_id + ",\"language\":\"" + language_type + "\",\"code\":\"" + code + "\"}"
  109. ## print(payload)
  110. with open('wulin4.txt', 'w', encoding='utf-8', newline='') as f:
  111. f.write(payload)
  112. f.close()
  113. # with open('wulin4.txt', 'r', encoding='utf-8', newline='') as f:
  114. # payload=f.read()
  115. #f.close()
  116. #payload = payload.replace("\t","").replace(" ","")
  117. #with open('wulin4.txt', 'w', encoding='utf-8', newline='') as f:
  118. # f.write(payload)
  119. #f.close()
  120. results = submit(payload,problem_id)
  121. return results
  122. # 输入文件名,题号,语言种类
  123. #results = submit_handler('22.c','22','C')
  124. #print(results)
  125. #获取逻辑错误信息