| 45 | |
| 46 | |
| 47 | def submit_solution( |
| 48 | ws_url: str, |
| 49 | api_key: str, |
| 50 | challenge_code: str, |
| 51 | file_name: str, |
| 52 | content: str, |
| 53 | language: str, |
| 54 | accelerator: str, |
| 55 | action: str, |
| 56 | public: bool, |
| 57 | ) -> bool: |
| 58 | |
| 59 | ws = websocket.create_connection(ws_url, timeout=120) |
| 60 | try: |
| 61 | submission = { |
| 62 | "action": action, |
| 63 | "token": api_key, |
| 64 | "submission": { |
| 65 | "files": [{"name": file_name, "content": content}], |
| 66 | "language": language, |
| 67 | "accelerator": accelerator, |
| 68 | "mode": "accelerated", |
| 69 | "public": public, |
| 70 | "challengeCode": challenge_code, |
| 71 | }, |
| 72 | } |
| 73 | ws.send(json.dumps(submission)) |
| 74 | logger.info("Submitted %s", file_name) |
| 75 | |
| 76 | while True: |
| 77 | msg = ws.recv() |
| 78 | if not msg: |
| 79 | continue |
| 80 | data = json.loads(msg) |
| 81 | status = data.get("status") |
| 82 | output = data.get("output") |
| 83 | logger.info("Status: %s | Output: %s", status, output) |
| 84 | if status in {"success", "error", "timeout", "oom", "interrupted"}: |
| 85 | return status == "success" |
| 86 | finally: |
| 87 | ws.close() |
| 88 | |
| 89 | |
| 90 | def main() -> int: |