Examples#
ac_core.auth#
- 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.contest#
- 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#
- 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#
- 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#
- 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#
- 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.url#
- ac_core.url.url_2_contest_id(url: str) str [source]
- Parameters:
url – example:
https://atcoder.jp/contests/agc030
- Returns:
contest id. e.g. ‘agc030’
Examples:
from ac_core.url import url_2_contest_id print(url_2_contest_id('https://atcoder.jp/contests/abc260/tasks/abc260_b'))