online-judge-tools / api-client

API client to develop tools for competitive programming
MIT License
67 stars 21 forks source link
api-client atcoder automation codeforces competitive-programming network programming-contests scraping

online-judge-tools/api-client

test Documentation Status PyPI PyPI

What is this?

This is an API client for various online judges, used as the backend library of oj command. You can use the Python library (onlinejudge module) and the command-line interface (oj-api command) which talks JSON compatible with jmerle/competitive-companion.

How to install

$ pip3 install online-judge-api-client

Supported websites

website get sample cases get system cases get metadata get contest data login service submit code
Aizu Online Judge :heavy_check_mark: :heavy_check_mark:
Anarchy Golf :heavy_check_mark: :grey_question: (same to samples)
AtCoder :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
AtCoder Problems (virtual contests) :heavy_check_mark:
CodeChef :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :grey_question:
Codeforces :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :x: issue
CS Academy :heavy_check_mark:
Facebook Hacker Cup :heavy_check_mark:
Google Code Jam :heavy_check_mark:
Google Kick Start :heavy_check_mark:
HackerRank :heavy_check_mark: :heavy_check_mark: :grey_question: :heavy_check_mark:
Kagamiz Contest System :x: :grey_question: :heavy_check_mark:
Kattis :heavy_check_mark:
Library Checker :heavy_check_mark: :heavy_check_mark:
PKU JudgeOnline :heavy_check_mark:
Sphere Online Judge :heavy_check_mark:
Topcoder :heavy_check_mark: (archived problems only) :grey_question:
Toph :heavy_check_mark: :grey_question: :heavy_check_mark:
yukicoder :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :grey_question: :heavy_check_mark:

Instead of login-service, you can use oj command with Selenium as oj login https://.... This can login almost all services.

Supported subcommands of oj-api command

get-problem

oj-api get-problem PROBLEM_URL parses the given problem and prints the results as JSON compatible with jmerle/competitive-companion.

options

format

format (additional)

example

$ oj-api get-problem https://atcoder.jp/contests/arc100/tasks/arc100_b | jq .result
{
  "url": "https://atcoder.jp/contests/arc100/tasks/arc100_b",
  "name": "Equal Cut",
  "context": {
    "contest": {
      "url": "https://atcoder.jp/contests/arc100",
      "name": "AtCoder Regular Contest 100"
    },
    "alphabet": "D"
  },
  "memoryLimit": 1024,
  "timeLimit": 2000,
  "tests": [
    {
      "input": "5\n3 2 4 1 2\n",
      "output": "2\n"
    },
    {
      "input": "10\n10 71 84 33 6 47 23 25 52 64\n",
      "output": "36\n"
    },
    {
      "input": "7\n1 2 3 1000000000 4 5 6\n",
      "output": "999999994\n"
    }
  ]
}

get-problem --compatibility

oj-api get-problem --compatibility PROBLEM_URL is the variant of get-problem strictly compatible with jmerle/competitive-companion.

format

See the document of jmerle/competitive-companion.

example

{
  "name": "D. Equal Cut",
  "group": "AtCoder Regular Contest 100",
  "url": "https://atcoder.jp/contests/arc100/tasks/arc100_b",
  "interactive": false,
  "memoryLimit": 1024,
  "timeLimit": 2000,
  "tests": [
    {
      "input": "5\n3 2 4 1 2\n",
      "output": "2\n"
    },
    {
      "input": "10\n10 71 84 33 6 47 23 25 52 64\n",
      "output": "36\n"
    },
    {
      "input": "7\n1 2 3 1000000000 4 5 6\n",
      "output": "999999994\n"
    }
  ],
  "testType": "single",
  "input": {
    "type": "stdin"
  },
  "output": {
    "type": "stdout"
  },
  "languages": {
    "java": {
      "mainClass": "Main",
      "taskClass": "Task"
    }
  }
}

get-contest

oj-api get-contest CONTEST_URL parses the given contest and prints the results as JSON.

format

example

$ oj-api get-contest https://atcoder.jp/contests/arc100 | jq .result
{
  "url": "https://atcoder.jp/contests/arc100",
  "name": "AtCoder Regular Contest 100",
  "problems": [
    {
      "url": "https://atcoder.jp/contests/arc100/tasks/arc100_a",
      "name": "Linear Approximation",
      "context": {
        "contest": {
          "url": "https://atcoder.jp/contests/arc100",
          "name": "AtCoder Regular Contest 100"
        },
        "alphabet": "C"
      }
    },
    {
      "url": "https://atcoder.jp/contests/arc100/tasks/arc100_b",
      "name": "Equal Cut",
      "context": {
        "contest": {
          "url": "https://atcoder.jp/contests/arc100",
          "name": "AtCoder Regular Contest 100"
        },
        "alphabet": "D"
      }
    },
    {
      "url": "https://atcoder.jp/contests/arc100/tasks/arc100_c",
      "name": "Or Plus Max",
      "context": {
        "contest": {
          "url": "https://atcoder.jp/contests/arc100",
          "name": "AtCoder Regular Contest 100"
        },
        "alphabet": "E"
      }
    },
    {
      "url": "https://atcoder.jp/contests/arc100/tasks/arc100_d",
      "name": "Colorful Sequences",
      "context": {
        "contest": {
          "url": "https://atcoder.jp/contests/arc100",
          "name": "AtCoder Regular Contest 100"
        },
        "alphabet": "F"
      }
    }
  ]
}

get-service

oj-api get-service SERVICE_URL prints the data of the service.

options

format

example

$ oj-api get-service https://atcoder.jp/ --list-contests | jq .result
{
  "url": "https://atcoder.jp/",
  "name": "AtCoder",
  "contests": [
    {
      "url": "https://atcoder.jp/contests/abc162",
      "name": "AtCoder Beginner Contest 162"
    },
    {
      "url": "https://atcoder.jp/contests/judge-update-202004",
      "name": "Judge System Update Test Contest 202004"
    },
    {
      "url": "https://atcoder.jp/contests/abc161",
      "name": "AtCoder Beginner Contest 161"
    },
    {
      "url": "https://atcoder.jp/contests/abc160",
      "name": "AtCoder Beginner Contest 160"
    },
    ...
  ]
}

login-service

USERNAME=USERNAME PASSWORD=PASSWORD oj-api login-service SERVICE_URL logs in the given service.

options

format

example

$ USERNAME=kimiyuki PASSWORD='????????????????' oj-api login-service https://atcoder.jp/ | jq .result
{
  "loggedIn": true
}

submit-code

oj-api submit-code PROBLEM_URL --file FILE --language LANGUAGE_ID submits the file to the given problem. You can obtrain the LANGUAGE_ID from the list availableLanguages of oj-api get-problem --full PROBLEM_URL or the guess-language-id subcommand.

format

example

$ oj-api submit-code https://atcoder.jp/contests/abc160/tasks/abc160_a --file main.py --language 3023 | jq .result
{
  "url": "https://atcoder.jp/contests/abc160/submissions/11991846"
}

guess-language-id

oj-api guess-language-id PROBLEM_URL --file FILE guesses the language id to submit the file to the given problem.

format

example

$ oj-api guess-language-id http://codeforces.com/contest/1373/problem/A --file=main.py | jq .result
{
  "id": "31",
  "description": "Python 3.7.2",
}

JSON API responses

format

example

$ USERNAME=chokudai PASSWORD=hoge oj-api login-service https://atcoder.jp/ | jq .
{
  "status": "error",
  "messages": [
    "onlinejudge.type.LoginError: failed to login"
  ],
  "result": null
}

Tips

For end-users who don't develop any programs:

For developers of programs which use oj-api: