competitive programming scripts on Linux
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.

46 lines
1.2 KiB

3 years ago
  1. #!/usr/bin/env python3
  2. import os
  3. import sys
  4. import http.server
  5. import subprocess
  6. import json
  7. #script to download sample cases.
  8. def listen(*, timeout=None):
  9. json_data = None
  10. class CompetitiveCompanionHandler(http.server.BaseHTTPRequestHandler):
  11. def do_POST(self):
  12. nonlocal json_data
  13. json_data = json.load(self.rfile)
  14. with http.server.HTTPServer(('127.0.0.1', 10046), CompetitiveCompanionHandler) as server:
  15. server.timeout = timeout
  16. server.handle_request()
  17. if json_data is None:
  18. print("failed")
  19. print(json_data)
  20. return json_data
  21. def create_tests():
  22. prob = listen()
  23. #prob is a dictionary containing all of json data
  24. if prob is None:
  25. return
  26. cnt = 1
  27. for test in prob["tests"]:
  28. #create a .in and .out file
  29. name = "Sample" + str(cnt)
  30. #create new files and write the required cases to there.
  31. os.system("touch " + name + ".in")
  32. os.system("touch " + name + ".out")
  33. with open(name + ".in", "w") as inp:
  34. inp.write(test["input"])
  35. with open(name + ".out", "w") as op:
  36. op.write(test["output"])
  37. cnt += 1
  38. create_tests()