選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

127 行
4.4 KiB

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