Welcome to online-judge-tools’s documentation!

onlinejudge

onlinejudge package

Subpackages

onlinejudge.service package
Submodules
onlinejudge.service.anarchygolf module

the module for Anarchy Golf (http://golf.shinh.org/)

class onlinejudge.service.anarchygolf.AnarchyGolfProblem(*, problem_id)[source]

Bases: onlinejudge.type.Problem

download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

classmethod from_url(url)[source]
Return type

Optional[AnarchyGolfProblem]

get_service()[source]
Return type

AnarchyGolfService

get_url()[source]
Return type

str

class onlinejudge.service.anarchygolf.AnarchyGolfService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Return type

Optional[AnarchyGolfService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Return type

str

onlinejudge.service.aoj module

the module for Aizu Online Judge (http://judge.u-aizu.ac.jp/onlinejudge/)

note

There is the offcial API http://developers.u-aizu.ac.jp/index

class onlinejudge.service.aoj.AOJArenaProblem(*, arena_id, alphabet)[source]

Bases: onlinejudge.type.Problem

Variables
  • arena_idstr. for example, RitsCamp19Day2

  • alphabetstr

New in version 6.1.0.

download_content(*, session=None)[source]
Raises

NotImplementedError

download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

download_system_cases(*, session=None)[source]
Raises

NotLoggedInError

Return type

List[TestCase]

classmethod from_url(url)[source]
Return type

Optional[AOJArenaProblem]

get_problem_id(*, session=None)[source]
Note

use http://developers.u-aizu.ac.jp/api?key=judgeapi%2Farenas%2F%7BarenaId%7D%2Fproblems_GET

Return type

str

get_service()[source]
Return type

AOJService

get_url()[source]
Return type

str

class onlinejudge.service.aoj.AOJProblem(*, problem_id)[source]

Bases: onlinejudge.type.Problem

Variables

problem_idstr like DSL_1_A or 2256

download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

download_system_cases(*, session=None)[source]
Raises

NotLoggedInError

Return type

List[TestCase]

classmethod from_url(url)[source]
Return type

Optional[AOJProblem]

get_service()[source]
Return type

AOJService

get_url()[source]
Return type

str

class onlinejudge.service.aoj.AOJService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Return type

Optional[AOJService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Return type

str

onlinejudge.service.atcoder module

the module for AtCoder (https://atcoder.jp/)

note

There are some useful endpoints:

note

There is an unofficial API https://github.com/kenkoooo/AtCoderProblems

note

Some methods not inherited from classes onlinejudge.type may be modified in future, because the specification is not fixed yet.

class onlinejudge.service.atcoder.AtCoderContest(*, contest_id)[source]

Bases: onlinejudge.type.Contest

Variables

contest_idstr

download_data(*, session=None, lang='en')[source]
Return type

AtCoderContestDetailedData

classmethod from_url(url)[source]
Parameters

url (str) – example:

Return type

Optional[AtCoderContest]

get_service()[source]
Return type

AtCoderService

get_url(*, type=None, lang=None)[source]
Return type

str

iterate_submission_data_where(*, me=False, problem_id=None, language_id=None, status=None, user_glob=None, order=None, desc=False, lang=None, pages=None, session=None)[source]
Note

If you use certain combination of options, then the results may not correct when there are new submissions while crawling.

Parameters
  • status (Optional[str]) – must be one of AC, WA, TLE, MLE, RE, CLE, OLE, IE, WJ, WR, or Judging

  • order (Optional[str]) – must be one of created, score, source_length, time_consumption, or memory_consumption

  • me (bool) – use the …/submissions/me page instead of …/submission

  • user_glob (Optional[str]) – is used as the value of f.User query parameter

  • language_id (Optional[NewType()(LanguageId, str)]) – is used as the value of f.Language query parameter

  • lang (Optional[str]) – must be one of ja, en

  • pages (Optional[Iterator[int]]) – is an iterator to list the page numbers to GET

Return type

Iterator[AtCoderSubmissionData]

iterate_submissions(*, session=None)[source]
Note

in implementation, use “ORDER BY created DESC” to list all submissions even when there are new submissions

Return type

Iterator[AtCoderSubmission]

iterate_submissions_where(**kwargs)[source]
Return type

Iterator[AtCoderSubmission]

list_problem_data(*, session=None)[source]
Return type

List[AtCoderProblemData]

list_problems(*, session=None)[source]
Return type

List[AtCoderProblem]

class onlinejudge.service.atcoder.AtCoderContestData(*, contest, duration, lang, name, rated_range, response, session, start_time, timestamp)[source]

Bases: onlinejudge.type.ContestData

Variables
property contest
Return type

AtCoderContest

property html
Return type

bytes

property name
Return type

str

property response
Return type

Response

property session
Return type

Session

property timestamp
Return type

datetime

class onlinejudge.service.atcoder.AtCoderContestDetailedData(*, can_participate, penalty, **kwargs)[source]

Bases: onlinejudge.service.atcoder.AtCoderContestData

Variables
class onlinejudge.service.atcoder.AtCoderProblem(*, contest_id, problem_id)[source]

Bases: onlinejudge.type.Problem

Variables
  • contest_idstr

  • problem_idstr

Note

AtCoder has problems independently from contests. Therefore the notions contest_id, alphabet, and url don’t belong to problems itself.

download_data(*, session=None)[source]
Raises

Exception – if no such problem exists

Return type

AtCoderProblemDetailedData

download_input_format(*, session=None)[source]
Raises

Exception – if no such problem exists

Return type

Optional[str]

download_sample_cases(*, session=None)[source]
Raises
  • requests.exceptions.HTTPError – if no such problem exists

  • SampleParseError – if parsing failed

Return type

List[TestCase]

classmethod from_url(s)[source]
Return type

Optional[AtCoderProblem]

get_available_languages(*, session=None)[source]
Raises

NotLoggedInError

Return type

List[Language]

get_contest()[source]
Return type

AtCoderContest

get_name(*, session=None)[source]
Return type

str

get_service()[source]
Return type

AtCoderService

get_url(*, type=None, lang=None)[source]
Return type

str

iterate_submissions(*, session=None)[source]
Note

in implementation, use “ORDER BY created DESC” to list all submissions even when there are new submissions

Return type

Iterator[AtCoderSubmission]

iterate_submissions_where(**kwargs)[source]
Return type

Iterator[AtCoderSubmission]

submit_code(code, language_id, *, filename=None, session=None)[source]
Raises
Return type

AtCoderSubmission

class onlinejudge.service.atcoder.AtCoderProblemData(*, alphabet, memory_limit_byte, name, problem, response, session, time_limit_msec, timestamp, html=None)[source]

Bases: onlinejudge.type.ProblemData

Note

AtCoderProblemData is obtained the list page (e.g. https://atcoder.jp/contests/agc001/tasks )

Variables
property html
Return type

bytes

property name

for example of Problem:

  • 器物損壊!高橋君

  • AtCoDeerくんと変なじゃんけん / AtCoDeer and Rock-Paper

  • Xor Sum

Return type

str

property problem
Return type

AtCoderProblem

property response
Return type

Optional[Response]

property session
Return type

Optional[Session]

property timestamp
Return type

Optional[datetime]

class onlinejudge.service.atcoder.AtCoderProblemDetailedData(*, available_languages, input_format, sample_cases, score, **kwargs)[source]

Bases: onlinejudge.service.atcoder.AtCoderProblemData

Note

AtCoderProblemDetailedData is obtained the problem page (e.g. https://atcoder.jp/contests/agc001/tasks/agc001_a )

Variables
  • available_languagesOptional [ List [ Language ] ]

  • input_formatOptional [ str ]

  • sample_casesOptional [ List [ TestCase ] ]

  • scoreOptional [ float ]

classmethod from_html(html, *, problem, session=None, response=None, timestamp=None)[source]
Parameters

html (bytes) – must be a HTML of the new (beta) version of AtCoder

New in version 6.2.0.

Return type

AtCoderProblemDetailedData

property sample_cases
Return type

Optional[List[TestCase]]

class onlinejudge.service.atcoder.AtCoderService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Parameters

url (str) – example:

Return type

Optional[AtCoderService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Return type

str

get_url_of_login_page()[source]
Return type

str

get_user_history_url(user_id)[source]
Return type

str

is_logged_in(*, session=None)[source]
Return type

bool

iterate_contest_data(*, lang='ja', session=None)[source]
Parameters

lang (str) – must be ja (default) or en.

Note

lang=ja is required to see some Japanese-local contests.

Note

You can use lang=en to see the English names of contests.

Return type

Iterator[AtCoderContestData]

iterate_contests(*, lang='ja', session=None)[source]
Return type

Iterator[AtCoderContest]

login(*, get_credentials, session=None)[source]
Raises

LoginError

Return type

None

class onlinejudge.service.atcoder.AtCoderSubmission(*, contest_id, submission_id)[source]

Bases: onlinejudge.type.Submission

Variables
  • contest_idstr

  • submission_idstr

download_data(*, session=None)[source]
Note

Exec Time is undefined when the status is RE or TLE

Note

Memory is undefined when the status is RE or TLE

Return type

AtCoderSubmissionDetailedData

download_problem(*, session=None)[source]
Return type

AtCoderProblem

classmethod from_url(s)[source]
Return type

Optional[AtCoderSubmission]

get_problem()[source]
Raises

Exception

Note

There is no way to reconstruct problem_id without networking

Return type

AtCoderProblem

get_service()[source]
Return type

AtCoderService

get_url(*, type=None, lang=None)[source]
Return type

str

class onlinejudge.service.atcoder.AtCoderSubmissionData(*, code_size, exec_time_msec, language_name, memory_byte, problem, problem_id, response, score, session, status, submission, submission_time, timestamp, user_id)[source]

Bases: onlinejudge.type.SubmissionData

Variables
property problem
Return type

AtCoderProblem

property response
Return type

Optional[Response]

property session
Return type

Optional[Session]

property status
Return type

str

property submission
Return type

AtCoderSubmission

property timestamp
Return type

Optional[datetime]

class onlinejudge.service.atcoder.AtCoderSubmissionDetailedData(*, source_code, compile_error, test_sets, test_cases, **kwargs)[source]

Bases: onlinejudge.service.atcoder.AtCoderSubmissionData

property source_code
Return type

bytes

class onlinejudge.service.atcoder.AtCoderSubmissionTestCaseResult(*, case_name, status, exec_time_msec, memory_byte)[source]

Bases: object

Variables
  • case_namestr

  • statusstr

  • exec_time_msecint in millisecond

  • memory_byteint in byte

class onlinejudge.service.atcoder.AtCoderSubmissionTestSet(*, set_name, score, max_score, test_case_names)[source]

Bases: object

Variables
onlinejudge.service.codeforces module

the module for Codeforces (https://codeforces.com/)

note

There is the offcial API https://codeforces.com/api/help

class onlinejudge.service.codeforces.CodeforcesContest(*, contest_id, kind=None)[source]

Bases: onlinejudge.type.Contest

Variables
  • contest_idint

  • kindstr must be contest or gym

download_data(*, session=None)[source]
Return type

CodeforcesContestData

classmethod from_url(url)[source]
Return type

Optional[CodeforcesContest]

get_service()[source]
Return type

CodeforcesService

get_url()[source]
Return type

str

list_problem_data(*, session=None)[source]
Return type

List[CodeforcesProblemData]

list_problems(*, session=None)[source]
Return type

List[CodeforcesProblem]

class onlinejudge.service.codeforces.CodeforcesContestData(*, contest, duration_seconds, frozen, name, phase, relative_time_seconds, response, session, start_time_seconds, timestamp, type)[source]

Bases: onlinejudge.type.ContestData

property contest
Return type

CodeforcesContest

property json
Return type

bytes

property name
Return type

str

property response
Return type

Response

property session
Return type

Session

property timestamp
Return type

datetime

class onlinejudge.service.codeforces.CodeforcesProblem(*, contest_id, index, kind=None)[source]

Bases: onlinejudge.type.Problem

Variables
  • contest_idint

  • indexstr

  • kindstr must be contest or gym

download_data(*, session=None)[source]
Return type

CodeforcesProblemData

download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

classmethod from_url(url)[source]
Return type

Optional[CodeforcesProblem]

get_available_languages(*, session=None)[source]
Raises

NotLoggedInError

Return type

List[Language]

get_contest()[source]
Return type

CodeforcesContest

get_service()[source]
Return type

CodeforcesService

get_url()[source]
Return type

str

submit_code(code, language_id, *, filename=None, session=None)[source]
Raises
Return type

Submission

class onlinejudge.service.codeforces.CodeforcesProblemData(*, name, points, problem, rating, response, session, tags, timestamp, type)[source]

Bases: onlinejudge.type.ProblemData

property json
Return type

bytes

property name

for example of Problem:

  • 器物損壊!高橋君

  • AtCoDeerくんと変なじゃんけん / AtCoDeer and Rock-Paper

  • Xor Sum

Return type

str

property problem
Return type

CodeforcesProblem

property response
Return type

Response

property session
Return type

Session

property timestamp
Return type

datetime

class onlinejudge.service.codeforces.CodeforcesService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Return type

Optional[CodeforcesService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Return type

str

get_url_of_login_page()[source]
Return type

str

is_logged_in(*, session=None)[source]
Return type

bool

iterate_contest_data(*, is_gym=False, session=None)[source]
Return type

Iterator[CodeforcesContestData]

iterate_contests(*, is_gym=False, session=None)[source]
Return type

Iterator[CodeforcesContest]

login(*, get_credentials, session=None)[source]
Raises

LoginError

Return type

None

onlinejudge.service.csacademy module

the module for CS Academy (https://csacademy.com/)

class onlinejudge.service.csacademy.CSAcademyProblem(*, contest_name, task_name)[source]

Bases: onlinejudge.type.Problem

download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

classmethod from_url(url)[source]
Return type

Optional[CSAcademyProblem]

get_service()[source]
Return type

CSAcademyService

get_url()[source]
Return type

str

class onlinejudge.service.csacademy.CSAcademyService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Return type

Optional[CSAcademyService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Return type

str

onlinejudge.service.facebook module

the module for Facebook Hacker Cup (https://www.facebook.com/hackercup/)

New in version 6.5.0.

class onlinejudge.service.facebook.FacebookHackerCupProblem(*, problem_id)[source]

Bases: onlinejudge.type.Problem

Variables

problem_idint

download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

classmethod from_url(url)[source]
Return type

Optional[FacebookHackerCupProblem]

get_service()[source]
Return type

FacebookHackerCupService

get_url()[source]
Return type

str

class onlinejudge.service.facebook.FacebookHackerCupService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Return type

Optional[FacebookHackerCupService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Return type

str

onlinejudge.service.hackerrank module

the module for HackerRank (https://www.hackerrank.com/)

class onlinejudge.service.hackerrank.HackerRankProblem(contest_slug, challenge_slug)[source]

Bases: onlinejudge.type.Problem

download_sample_cases(*, session=None)[source]
Raises

NotImplementedError

Return type

List[TestCase]

download_system_cases(*, session=None)[source]
Raises

NotLoggedInError

Return type

List[TestCase]

classmethod from_url(url)[source]
Return type

Optional[HackerRankProblem]

get_available_languages(*, session=None)[source]
Return type

List[Language]

get_service()[source]
Return type

HackerRankService

get_url()[source]
Return type

str

submit_code(code, language_id, *, filename=None, session=None)[source]
Raises
Return type

Submission

class onlinejudge.service.hackerrank.HackerRankService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Return type

Optional[HackerRankService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Return type

str

get_url_of_login_page()[source]
Return type

str

is_logged_in(*, session=None)[source]
Return type

bool

onlinejudge.service.kattis module

the module for Kattis (https://open.kattis.com/)

class onlinejudge.service.kattis.KattisProblem(*, problem_id, contest_id=None, domain='open.kattis.com')[source]

Bases: onlinejudge.type.Problem

download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

classmethod from_url(url)[source]
Return type

Optional[KattisProblem]

get_service()[source]
Return type

KattisService

get_url(*, contests=True)[source]
Return type

str

class onlinejudge.service.kattis.KattisService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Return type

Optional[KattisService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Note

sometimes this URL is not correct, i.e. something like https://hanoi18.kattis.com/ exists

Return type

str

onlinejudge.service.poj module

the module for PKU JudgeOnline (http://poj.org/)

class onlinejudge.service.poj.POJProblem(*, problem_id)[source]

Bases: onlinejudge.type.Problem

download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

classmethod from_url(url)[source]
Return type

Optional[POJProblem]

get_service()[source]
Return type

POJService

get_url()[source]
Return type

str

class onlinejudge.service.poj.POJService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Return type

Optional[POJService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Return type

str

onlinejudge.service.topcoder module

the module for Topcoder (https://www.topcoder.com/)

note

There is the offcial API https://tcapi.docs.apiary.io/

note

only the Marathon Match is supported

class onlinejudge.service.topcoder.TopcoderLongContestProblem(*, rd, cd=None, compid=None, pm=None)[source]

Bases: onlinejudge.type.Problem

download_individual_results_feed(*, cr, session=None)[source]

New in version 6.2.0: This method may be deleted in future.

Return type

TopcoderLongContestProblemIndividualResultsFeed

download_overview(*, session=None)[source]

New in version 6.2.0: This method may be deleted in future.

Return type

List[TopcoderLongContestProblemOverviewRow]

download_sample_cases(*, session=None)[source]
Raises

NotImplementedError

Return type

List[TestCase]

download_standings(*, session=None)[source]
Raises

Exception – if redirected to module=ViewOverview page

New in version 6.2.0: This method may be deleted in future.

Return type

List[TopcoderLongContestProblemStandingsRow]

download_system_test(*, test_case_id, session=None)[source]
Raises

NotLoggedInError

Note

You need to parse this result manually.

New in version 6.2.0: This method may be deleted in future.

Return type

str

classmethod from_url(url)[source]
Return type

Optional[TopcoderLongContestProblem]

get_available_languages(*, session=None)[source]
Return type

List[Language]

get_service()[source]
Return type

TopcoderService

get_url()[source]
Return type

str

submit_code(code, language_id, *, filename=None, session=None, kind='example')[source]
Parameters

kind (str) – must be one of example (default) or full

Raises
Return type

Submission

class onlinejudge.service.topcoder.TopcoderLongContestProblemIndividualResultsFeed(round_id, coder_id, handle, submissions, testcases)

Bases: tuple

property coder_id

Alias for field number 1

property handle

Alias for field number 2

property round_id

Alias for field number 0

property submissions

Alias for field number 3

property testcases

Alias for field number 4

class onlinejudge.service.topcoder.TopcoderLongContestProblemIndividualResultsFeedSubmission(number, score, language, time)

Bases: tuple

property language

Alias for field number 2

property number

Alias for field number 0

property score

Alias for field number 1

property time

Alias for field number 3

class onlinejudge.service.topcoder.TopcoderLongContestProblemIndividualResultsFeedTestCase(test_case_id, score, processing_time, fatal_error_ind)

Bases: tuple

property fatal_error_ind

Alias for field number 3

property processing_time

Alias for field number 2

property score

Alias for field number 1

property test_case_id

Alias for field number 0

class onlinejudge.service.topcoder.TopcoderLongContestProblemOverviewRow(rank, handle, provisional_rank, provisional_score, final_score, language, cr)

Bases: tuple

property cr

Alias for field number 6

property final_score

Alias for field number 4

property handle

Alias for field number 1

property language

Alias for field number 5

property provisional_rank

Alias for field number 2

property provisional_score

Alias for field number 3

property rank

Alias for field number 0

class onlinejudge.service.topcoder.TopcoderLongContestProblemStandingsRow(handle, score, rank, last_submission_time, language, example_tests, submissions, cr)

Bases: tuple

property cr

Alias for field number 7

property example_tests

Alias for field number 5

property handle

Alias for field number 0

property language

Alias for field number 4

property last_submission_time

Alias for field number 3

property rank

Alias for field number 2

property score

Alias for field number 1

property submissions

Alias for field number 6

class onlinejudge.service.topcoder.TopcoderService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Return type

Optional[TopcoderService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Return type

str

get_url_of_login_page()[source]
is_logged_in(*, session=None)[source]

New in version 6.2.0.

Return type

bool

login(*, get_credentials, session=None)[source]
Raises

LoginError

Return type

None

onlinejudge.service.toph module

the module for Toph (https://toph.co/)

class onlinejudge.service.toph.TophProblem(*, problem_id, contest_id=None)[source]

Bases: onlinejudge.type.Problem

Variables
  • problem_idstr

  • contest_idOptional [ str ]

download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

classmethod from_url(s)[source]
Return type

Optional[TophProblem]

get_available_languages(*, session=None)[source]
Raises

NotImplementedError

Return type

List[Language]

get_service()[source]
Return type

TophService

get_url()[source]
Return type

str

submit_code(code, language_id, *, filename=None, session=None)[source]
Raises
Return type

Submission

class onlinejudge.service.toph.TophService[source]

Bases: onlinejudge.type.Service

classmethod from_url(s)[source]
Return type

Optional[TophService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_url()[source]
Return type

str

get_url_of_login_page()[source]
Return type

str

is_logged_in(*, session=None)[source]
Return type

bool

onlinejudge.service.yukicoder module

the module for yukicoder (https://yukicoder.me/)

note

There is the official API https://petstore.swagger.io/?url=https://yukicoder.me/api/swagger.yaml

class onlinejudge.service.yukicoder.YukicoderProblem(*, problem_no=None, problem_id=None)[source]

Bases: onlinejudge.type.Problem

download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

download_system_cases(*, session=None)[source]
Raises

NotLoggedInError

Return type

List[TestCase]

classmethod from_url(url)[source]
Return type

Optional[YukicoderProblem]

get_available_languages(*, session=None)[source]
Return type

List[Language]

get_input_format(*, session=None)[source]
Return type

Optional[str]

get_service()[source]
Return type

YukicoderService

get_url()[source]
Return type

str

submit_code(code, language_id, *, filename=None, session=None)[source]
Raises

NotLoggedInError

Return type

Submission

class onlinejudge.service.yukicoder.YukicoderService[source]

Bases: onlinejudge.type.Service

classmethod from_url(url)[source]
Return type

Optional[YukicoderService]

get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

get_problems(*, page, comp_problem=True, other=False, sort=None, session=None)[source]

Deprecated since version 6.0.0: This method may be deleted in future.

Return type

List[Any]

get_solved(*args, **kwargs)[source]

Deprecated since version 6.0.0: This method may be deleted in future.

Return type

List[Dict[str, Any]]

get_submissions(*, page, status=None, session=None)[source]

Deprecated since version 6.0.0: This method may be deleted in future.

Return type

List[Any]

get_url()[source]
Return type

str

get_url_of_login_page()[source]
get_user(*args, **kwargs)[source]

Deprecated since version 6.0.0: This method may be deleted in future.

Return type

Dict[str, Any]

get_user_favorite(id, *, session=None)[source]

Deprecated since version 6.0.0: This method may be deleted in future.

Return type

List[Any]

get_user_favorite_problem(id, session=None)[source]

Deprecated since version 6.0.0: This method may be deleted in future.

Return type

List[Any]

get_user_favorite_wiki(id, *, session=None)[source]

Deprecated since version 6.0.0: This method may be deleted in future.

Return type

List[Any]

is_logged_in(*, session=None, method=None)[source]
Return type

bool

Module contents

Submodules

onlinejudge.dispatch module
onlinejudge.dispatch.services
Type

List [ Type [ onlinejudge.type.Service ] ]

contains classes to use for service_from_url()

onlinejudge.dispatch.problems
Type

List [ Type [ onlinejudge.type.Problem ] ]

contains classes to use for problem_from_url()

onlinejudge.dispatch.submissions
Type

List [ Type [ onlinejudge.type.Submission ] ]

contains classes to use for submission_from_url()

onlinejudge.dispatch.contest_from_url(url)[source]
Return type

Optional[Contest]

onlinejudge.dispatch.problem_from_url(url)[source]
>>> onlinejudge.dispatch.problem_from_url("https://atcoder.jp/contests/abc077/tasks/arc084_b")
<onlinejudge.service.atcoder.AtCoderProblem object at 0x7fa0538ead68>
>>> onlinejudge.dispatch.problem_from_url("https://codeforces.com/contest/1012/problem/D")
<onlinejudge.service.codeforces.CodeforcesProblem object at 0x7fa05a916710>
Return type

Optional[Problem]

onlinejudge.dispatch.service_from_url(url)[source]
Return type

Optional[Service]

onlinejudge.dispatch.submission_from_url(url)[source]
Return type

Optional[Submission]

onlinejudge.type module
class onlinejudge.type.Contest[source]

Bases: abc.ABC

Note

Contest represents just a URL of a contest, without the data of the contest.

download_data(*, session=None)[source]
Return type

ContestData

abstract classmethod from_url(s)[source]
Return type

Optional[Contest]

abstract get_service()[source]
Return type

Service

abstract get_url()[source]
Return type

str

iterate_submissions(*, session=None)[source]
Return type

Iterator[Submission]

list_problems(*, session=None)[source]
Return type

List[Problem]

class onlinejudge.type.ContestData[source]

Bases: onlinejudge.type.DownloadedData

abstract property contest
Return type

Contest

abstract property name
Return type

str

property service
Return type

Service

url()[source]
Return type

str

class onlinejudge.type.DownloadedData[source]

Bases: abc.ABC

Note

DownloadedData and its subclasses represent contents which are obtained by network access. The values may depends your session. DownloadedData とそのサブクラスは、ネットワークアクセスの結果得られるようなデータを表現します。その値はログイン状況などにより接続のたびに変化することがあります。

property html
Return type

Optional[bytes]

property json
Return type

Optional[bytes]

property response
Return type

Optional[Response]

property session
Return type

Optional[Session]

property timestamp
Return type

Optional[datetime]

abstract property url
Return type

str

class onlinejudge.type.Language(id, name)

Bases: tuple

Variables
property id

Alias for field number 0

property name

Alias for field number 1

onlinejudge.type.LanguageId(x)
Note

This is just a NewType -ed str not, but you should not use this other than a label.

exception onlinejudge.type.LoginError[source]

Bases: RuntimeError

exception onlinejudge.type.NotLoggedInError[source]

Bases: RuntimeError

class onlinejudge.type.Problem[source]

Bases: abc.ABC

Note

Problem represents just a URL of a problem, without the data of the problem. Problem はちょうど問題の URL のみを表現します。キャッシュや内部状態は持ちません。

download_data(*, session=None)[source]
Return type

ProblemData

abstract download_sample_cases(*, session=None)[source]
Raises

SampleParseError

Return type

List[TestCase]

download_system_cases(*, session=None)[source]
Raises

NotLoggedInError

Return type

List[TestCase]

abstract classmethod from_url(s)[source]
Return type

Optional[Problem]

get_available_languages(*, session=None)[source]
Return type

List[Language]

get_contest()[source]
Return type

Contest

abstract get_service()[source]
Return type

Service

abstract get_url()[source]
Return type

str

submit_code(code, language_id, *, filename=None, session=None)[source]
Parameters
Raises
Return type

Submission

class onlinejudge.type.ProblemData[source]

Bases: onlinejudge.type.DownloadedData

property contest
Return type

Contest

abstract property name

for example of Problem:

  • 器物損壊!高橋君

  • AtCoDeerくんと変なじゃんけん / AtCoDeer and Rock-Paper

  • Xor Sum

Return type

str

abstract property problem
Return type

Problem

property sample_cases
Return type

Optional[List[TestCase]]

property service
Return type

Service

url()[source]
Return type

str

exception onlinejudge.type.SampleParseError[source]

Bases: RuntimeError

class onlinejudge.type.Service[source]

Bases: abc.ABC

abstract classmethod from_url(s)[source]
Return type

Optional[Service]

abstract get_name()[source]

example:

  • AtCoder

  • Codeforces

  • PKU JudgeOnline

Note

If you want something like identifier (e.g. atcoder, codeforces or poj), you can use a domain obtained from get_url().

Return type

str

abstract get_url()[source]
Return type

str

get_url_of_login_page()[source]
Return type

str

is_logged_in(*, session=None)[source]
Return type

bool

iterate_contests(*, session=None)[source]
Return type

Iterator[Contest]

login(*, get_credentials, session=None)[source]
Parameters

get_credentials (Callable[[], Tuple[str, str]]) – returns a tuple of (username, password)

Raises

LoginError

Return type

None

class onlinejudge.type.Submission[source]

Bases: abc.ABC

download_data(*, session=None)[source]
Return type

SubmissionData

abstract classmethod from_url(s)[source]
Return type

Optional[Submission]

get_contest()[source]
Return type

Contest

abstract get_problem()[source]
Return type

Problem

abstract get_service()[source]
Return type

Service

abstract get_url()[source]
Return type

str

class onlinejudge.type.SubmissionData[source]

Bases: onlinejudge.type.DownloadedData

property contest
Return type

Contest

property problem
Return type

Problem

property service
Return type

Service

property source_code
Return type

bytes

abstract property status
Return type

str

abstract property submission
Return type

Submission

url()[source]
Return type

str

exception onlinejudge.type.SubmissionError[source]

Bases: RuntimeError

class onlinejudge.type.TestCase(name, input_name, input_data, output_name, output_data)

Bases: tuple

property input_data

Alias for field number 2

property input_name

Alias for field number 1

property name

Alias for field number 0

property output_data

Alias for field number 4

property output_name

Alias for field number 3

Module contents

How to run CI on your library for competitive programming (Japanese)

あなたが競技プログラマなら、おそらく自分用の競技プログラミング用のライブラリを内製していることでしょう。 そのようなライブラリには「そのライブラリを使った提出が既存の問題で AC することを確認する」という形の手動でのテストが行われるのが通常です。

しかしこれはとても面倒な作業です。 そして、単に忘れてしまったり、「修正は 1 行だけなので提出してテストしなくてもいいかな」などと言い訳して省略されてしまったりします。 そのようなライブラリにはきっとバグが潜んでいることでしょう。

ではどうすればよいでしょうか? もちろんこれは自動化によって解決できます。

Test Script

online-judge-tools には、ライブラリのテストに利用できる機能があります。 それらを組み合わせればテストの自動化が可能です。

例えば以下のようなシェルスクリプトを書いておくとよいでしょう。 まず .test.cpp という拡張子を持つファイルを作り、その中で #define PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp のような形で問題を指定しておきます (例: union_find_tree.test.cpp)。 するとこのスクリプトは、そのような拡張子のファイルを探し、自動でコードをコンパイルし、システムテストの入出力を自動で取得し、テストをしてくれます。 ローカルでの実行なのでサーバには比較的やさしいです。

#!/bin/bash
set -e
which oj > /dev/null

CXX=${CXX:-g++}
CXXFLAGS="${CXXFLAGS:--std=c++14 -O2 -Wall -g}"
ulimit -s unlimited

run() {
    file="$1"
    url="$(grep -o '^# *define \+PROBLEM \+\(https\?://.*\)' < "$file" | sed 's/.* http/http/')"
    dir=test/$(echo -n "$url" | md5sum | sed 's/ .*//')
    mkdir -p ${dir}
    $CXX $CXXFLAGS -I . -o ${dir}/a.out "$file"
    if [[ -n ${url} ]] ; then
        if [[ ! -e ${dir}/test ]] ; then
            sleep 2
            oj download --system "$url" -d ${dir}/test
        fi
        oj test --tle 10 --c ${dir}/a.out -d ${dir}/test
    else
        ${dir}/a.out
    fi
}

if [ $# -eq 0 ] ; then
    for f in $(find . -name \*.test.cpp) ; do
        run $f
    done
else
    for f in "$@" ; do
        run "$f"
    done
fi

ただし実質的に AOJ にしか対応していないので注意してください。 Codeforces はシステムテストのケースを配布してくれていませんし、 AtCoder は配布してくれてはいますが DropBox 経由なので自動化が困難なためです。

このスクリプトはあくまで一例であり、「Python にも対応させたい」「差分だけテストしたい」などの要求がある場合は各々で拡張してください (例: test.sh)。

Continuous Integration

「実行すると自動でテストしてくれるスクリプトがある」というだけではまだ不足です。 なぜならそのスクリプト自体は人間が手動で実行しなければならないためです。 この問題を解決するものは Continuous Integration (CI) と呼ばれます。

CI とは、自動で継続的にテストを行う仕組みや運用のことです。 GitHub のリポジトリにコミットが追加されるたびに自動でテストが実行されるようにしておく、というのはその例です。

もしあなたがライブラリを GitHub 上で管理しているのなら、 CI の導入は簡単です。 CI を実行してくれるサービスのひとつである Travis CI を利用しましょう。 Travis CI のページ https://travis-ci.org/ から登録してライブラリの GitHub レポジトリとの連携を有効化し、前節のシェルスクリプトを test.sh という名前で保存しているとき、以下の内容の .travis.yml というファイルを作れば終了です。

language: cpp
compiler:
    - clang
    - gcc
dist: xenial
addons:
    apt:
        packages:
            - python3
            - python3-pip
            - python3-setuptools

before_install:
    - pip3 install -U setuptools
    - pip3 install -U online-judge-tools=='6.*'
script:
    - bash test.sh

自動で実行されたテスト結果は Travis CI 上のページ (例: https://travis-ci.org/kmyk/competitive-programming-library) などから見ることができます。 https://img.shields.io/travis/USER/REPO/master.svg の形の URL から badge のようなバッジを生成できるので、これを README に貼っておくのもよいでしょう。 このバッチはテストの成功失敗に応じて色が勝手に変化します。

Examples

上で説明したものが実際に利用されている例として次のふたつを挙げておきます。

他にも CI を回している競プロライブラリはあり、例えば以下が知られています。

Indices and tables