ac_core package#
Subpackages#
Submodules#
ac_core.auth module#
- ac_core.auth.fetch_login(http_util: HttpUtilInterface, username: str, password: str) bool [source]#
This method will use
http_util
for login request andis_logged_in()
for login check- Parameters:
http_util – a http instance, for example
requests.session()
username – AtCoder username
password – AtCoder password
- Returns:
if it is successful post and logged
- Examples:
from ac_core.auth import fetch_login, is_logged_in import requests h = requests.session() #h = Helper(requests.session()) print(is_logged_in(h)) print(fetch_login(h, 'username', 'password')) print(is_logged_in(h))
- ac_core.auth.is_logged_in(http_util: HttpUtilInterface) bool [source]#
This method will use
http_util
for login check by visit atcoder site and parse html- Parameters:
http_util (HttpUtilInterface) – a http instance, for example
requests.session()
- Returns:
if it is successful logged in.
- Examples:
from ac_core.auth import fetch_login, is_logged_in import requests h = requests.session() #h = Helper(requests.session()) print(is_logged_in(h)) print(fetch_login(h, 'username', 'password')) print(is_logged_in(h))
ac_core.constant module#
ac_core.contest module#
- class ac_core.contest.FetchProblemResult(id: str, url: str, name: str, score: int, time_limit_msec: int, memory_limit_kb: int, tests: List[ac_core.modal.problem_test_case.ProblemTestCase])[source]#
Bases:
object
- id: str#
- memory_limit_kb: int#
- name: str#
- score: int#
- tests: List[ProblemTestCase]#
- time_limit_msec: int#
- url: str#
- class ac_core.contest.FetchResult(start_time: int, end_time: int, name: str, url: str, problems: List[ac_core.contest.FetchProblemResult])[source]#
Bases:
object
- end_time: int#
- name: str#
- problems: List[FetchProblemResult]#
- start_time: int#
- url: str#
- class ac_core.contest.ParserProblemResult(id: str, url: str, name: str, time_limit_msec: int, memory_limit_kb: int)[source]#
Bases:
object
- id: str#
- memory_limit_kb: int#
- name: str#
- time_limit_msec: int#
- url: str#
- class ac_core.contest.ParserResult(start_time: int, end_time: int, name: str, url: str, problems: List[ac_core.contest.ParserProblemResult])[source]#
Bases:
object
- end_time: int#
- name: str#
- problems: List[ParserProblemResult]#
- start_time: int#
- url: str#
- class ac_core.contest.StandingStruct(AdditionalColumns: Any = None, Fixed: bool = False, StandingsData: List[ac_core.contest.StandingsDataStruct] = <factory>, TaskInfo: List[ac_core.contest.TaskInfoStruct] = <factory>, Translation: Any = None)[source]#
Bases:
object
- AdditionalColumns: Any = None#
- Fixed: bool = False#
- StandingsData: List[StandingsDataStruct]#
- TaskInfo: List[TaskInfoStruct]#
- Translation: Any = None#
- classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A #
- classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A #
- classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A] #
- to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None] #
- to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str #
- class ac_core.contest.StandingsDataStruct(Additional: Any = None, Affiliation: str = 'Peking University', AtCoderRank: int = 18, Competitions: int = 21, Country: str = 'CN', IsRated: bool = False, IsTeam: bool = False, OldRating: int = 3337, Rank: int = 1, Rating: int = 3337, TaskResults: Dict[str, ac_core.contest.TaskResultsStruct] = <factory>, TotalResult: ac_core.contest.TotalResultStruct = <factory>, UserIsDeleted: bool = False, UserName: str = 'jiangly', UserScreenName: str = 'jiangly')[source]#
Bases:
object
- Additional: Any = None#
- Affiliation: str = 'Peking University'#
- AtCoderRank: int = 18#
- Competitions: int = 21#
- Country: str = 'CN'#
- IsRated: bool = False#
- IsTeam: bool = False#
- OldRating: int = 3337#
- Rank: int = 1#
- Rating: int = 3337#
- TaskResults: Dict[str, TaskResultsStruct]#
- TotalResult: TotalResultStruct#
- UserIsDeleted: bool = False#
- UserName: str = 'jiangly'#
- UserScreenName: str = 'jiangly'#
- classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A #
- classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A #
- classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A] #
- to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None] #
- to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str #
- class ac_core.contest.TaskInfoStruct(Assignment: str = 'A', TaskName: str = 'Middle Letter', TaskScreenName: str = 'abc266_a')[source]#
Bases:
object
- Assignment: str = 'A'#
- TaskName: str = 'Middle Letter'#
- TaskScreenName: str = 'abc266_a'#
- classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A #
- classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A #
- classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A] #
- to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None] #
- to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str #
- class ac_core.contest.TaskResultsStruct(Additional: Any = None, Count: int = 1, Elapsed: int = 84000000000, Failure: int = 1, Frozen: bool = False, Penalty: int = 0, Pending: bool = False, Score: int = 10000, Status: int = 1, SubmissionID: int = 34368488)[source]#
Bases:
object
- Additional: Any = None#
- Count: int = 1#
- Elapsed: int = 84000000000#
- Failure: int = 1#
- Frozen: bool = False#
- Penalty: int = 0#
- Pending: bool = False#
- Score: int = 10000#
- Status: int = 1#
- SubmissionID: int = 34368488#
- classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A #
- classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A #
- classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A] #
- to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None] #
- to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str #
- class ac_core.contest.TotalResultStruct(Accepted: int = 8, Additional: Any = None, Count: int = 8, Elapsed: int = 2079000000000, Frozen: bool = False, Penalty: int = 0, Score: int = 320000)[source]#
Bases:
object
- Accepted: int = 8#
- Additional: Any = None#
- Count: int = 8#
- Elapsed: int = 2079000000000#
- Frozen: bool = False#
- Penalty: int = 0#
- Score: int = 320000#
- classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A #
- classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A #
- classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A] #
- to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None] #
- to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str #
- ac_core.contest.fetch_standing(http_util: HttpUtilInterface, contest_id: str) StandingStruct [source]#
parse standings with http_util to struct
- Parameters:
http_util – e.g.
requests.session()
contest_id – the number in contest url, e.g.
abc123
- Examples:
import requests from ac_core.contest import fetch_standing print(fetch_standing(requests.session(), 'abc260'))
- ac_core.contest.fetch_tasks(http_util: HttpUtilInterface, contest_id: str) FetchResult [source]#
Fetch tasks with http_util and contest_id, this methods will parse both meta info of tasks and the detail page of tasks
- Examples:
import requests from ac_core.contest import fetch_tasks print(fetch_tasks(requests.session(), 'abc259')) # pass contest id
- ac_core.contest.fetch_tasks_meta(http_util: HttpUtilInterface, contest_id: str) ParserResult [source]#
fetch tasks page by http_util with contest_id, and then parse the tasks’ meta info with
parse_tasks()
- Parameters:
http_util – e.g.
requests.session()
contest_id – the number in contest url, e.g.
abc123
- Examples:
import requests from ac_core.contest import fetch_tasks_meta print(fetch_tasks_meta(requests.session(), 'abc260'))
- ac_core.contest.parse_standing(html: str) StandingStruct [source]#
parse json standings to struct
- Parameters:
html – the html data get from
https://atcoder.jp/contests/{contest_id}/standings/json
- Examples:
import requests from ac_core.contest import parse_standing r = requests.get('https://atcoder.jp/contests/abc260/standings/json') if r.status_code == 200: print(parse_standing(r.text)) # pass html
- ac_core.contest.parse_tasks(html: str) ParserResult [source]#
parse tasks page, this method will not parse the detail page(such as testcases) of the tasks
- Parameters:
html – the html source get from
https://atcoder.jp/contests/{contests_id}/tasks
- Examples:
import requests from ac_core.contest import parse_tasks r = requests.get('https://atcoder.jp/contests/abc260/tasks') if r.status_code == 200: print(parse_tasks(r.text)) # pass html
ac_core.language module#
- class ac_core.language.LanguageKV(value: str, text: str)[source]#
Bases:
object
- text: str#
- value: str#
- ac_core.language.fetch_language(http_util: HttpUtilInterface) List[LanguageKV] [source]#
Fetch language key and values, need to have logged into atcoder. You can use
ac_core.auth.fetch_login()
for login.- Parameters:
http_util – e.g.
requests.session()
- Examples:
import requests from ac_core.auth import fetch_login, is_logged_in from ac_core.language import fetch_language h = requests.session() fetch_login(h, 'username', 'password') assert(is_logged_in(h)) print(fetch_language(h))
ac_core.problem module#
- class ac_core.problem.ProblemResult(id: str, url: str, name: str, score: int, tests: List[ac_core.modal.problem_test_case.ProblemTestCase], contest_name: str, contest_url: str, contest_start: int, contest_end: int, memory_limit_kb: int, time_limit_msec: int)[source]#
Bases:
object
- contest_end: int#
- contest_name: str#
- contest_start: int#
- contest_url: str#
- id: str#
- memory_limit_kb: int#
- name: str#
- score: int#
- tests: List[ProblemTestCase]#
- time_limit_msec: int#
- url: str#
- exception ac_core.problem.SampleParseError(message: str = 'failed to parse samples')[source]#
Bases:
RuntimeError
- ac_core.problem.parse_task(html: str) ProblemResult [source]#
parse problem page html to structured data
- Parameters:
html – the html source get from
https://atcoder.jp/contests/{contest_id}/tasks/{problem_id}
- Examples:
import requests from ac_core.problem import parse_task r = requests.get('https://atcoder.jp/contests/abc260/tasks/abc260_a') if r.status_code == 200: print(parse_task(r.text))
ac_core.result module#
- class ac_core.result.SubmissionResult(id: str = '', url: str = '', score: int = 500, status: ac_core.result.SubmissionResult.Status = <Status.INIT: 'Init'>, time_cost_ms: int = 0, mem_cost_kb: int = 0, msg_txt: str = '')[source]#
Bases:
object
- class Status(value)[source]#
Bases:
Enum
An enumeration.
- AC: str = 'Accepted'#
- CE: str = 'Compilation Error'#
- INIT: str = 'Init'#
- PENDING: str = 'Waiting for Judging'#
- RE: str = 'Runtime Error'#
- RUNNING: str = 'Judging'#
- TLE: str = 'Time Limit Exceeded'#
- WA: str = 'Wrong Answer'#
- id: str = ''#
- mem_cost_kb: int = 0#
- msg_txt: str = ''#
- score: int = 500#
- time_cost_ms: int = 0#
- url: str = ''#
- ac_core.result.fetch_result(http_util: HttpUtilInterface, problem_url: str) SubmissionResult [source]#
parse submit result by http_util with problem_url.
You need logged in before using this method. This function will find your last submission for the problem.
- Parameters:
http_util – e.g.
requests.session()
problem_url – e.g.
https://atcoder.jp/contests/abc275/tasks/abc275_f
- Examples:
import requests from ac_core.auth import fetch_login, is_logged_in from ac_core.result import fetch_result h = requests.session() fetch_login(h, 'username', 'password') assert(is_logged_in(h)) print(fetch_result(h,'https://atcoder.jp/contests/abc275/tasks/abc275_f'))
- ac_core.result.fetch_result_by_url(http_util: HttpUtilInterface, json_url: str) SubmissionResult [source]#
parse submit result by http_util with submission json_url.
- Parameters:
http_util – e.g.
requests.session()
json_url – e.g.
https://atcoder.jp/contests/abc101/submissions/me/status/json?sids[]=5371077
- Examples:
import requests from ac_core.result import fetch_result_by_url print(fetch_result_by_url(requests.session(),'https://atcoder.jp/contests/abc101/submissions/me/status/json?sids[]=5371077'))
the structured data returned by
fetch_result()
has the submission json urlimport requests from ac_core.auth import fetch_login, is_logged_in from ac_core.result import fetch_result, fetch_result_by_url h = requests.session() fetch_login(h, 'username', 'password') assert(is_logged_in(h)) result = fetch_result(h,'https://atcoder.jp/contests/abc275/tasks/abc275_f') print(fetch_result_by_url(h,result.url))
- ac_core.result.parse_result(resp: str) SubmissionResult [source]#
parse submit result get from json result :param resp: the json result get from
https://atcoder.jp/contests/{contest_id}/submissions/me/status/json?sids[]={submision id}
- Examples:
import requests from ac_core.result import parse_result r = requests.get('https://atcoder.jp/contests/abc101/submissions/me/status/json?sids[]=5371077') if r.status_code == 200: print(parse_result(r.text)) # pass html
ac_core.submit module#
- ac_core.submit.fetch_fields(html: str) Dict[str, str] [source]#
parse necessary fields for requests header such as ‘csrf_token’
- Parameters:
html – the html source from
https://atcoder.jp/contests/{contest_id}/submit
- ac_core.submit.fetch_submit(http_util: HttpUtilInterface, problem_url: str, lang_id: str, source_code: str) HttpRespInterface [source]#
Submit code. You need logged in before using this method.
- Parameters:
http_util – e.g. requests.session()
problem_url – e.g.
'https://atcoder.jp/contests/abc285/tasks/abc285_a'
lang_id – e.g.
'4003'
forC++ (GCC 9.2.1)
, useac_core.language.fetch_language()
to get language listsource_code – the code text
- Examples:
import requests from ac_core.auth import fetch_login, is_logged_in from ac_core.submit import fetch_submit h = requests.session() fetch_login(h, 'username', 'password') assert(is_logged_in(h)) print(fetch_submit(h,'https://atcoder.jp/contests/abc285/tasks/abc285_a','4006','print("hello world.")'))
- ac_core.submit.problem_url_2_submit_url(problem_url: str) str [source]#
covert tool for problem_url to submit_url.
- Parameters:
problem_url – e.g.
'https://atcoder.jp/contests/abc285/tasks/abc285_a'
- Returns:
problem_url e.g.
'https://atcoder.jp/contests/abc285/submit'
- Examples:
from ac_core.submit import problem_url_2_submit_url print(problem_url_2_submit_url('https://atcoder.jp/contests/abc285/tasks/abc285_a'))