Examples#
codeforces_core.account module#
- async codeforces_core.account.async_login(http: AioHttpHelperInterface, handle: str, password: str, login_url='/enter?back=%2F', **kw) LoginResult [source]
This method will use
http
for login request, andis_user_logged_in()
for login check- Parameters:
handle – Codeforces handle
password – Codeforces password
- Returns:
if it is successful post and logged
Examples:
import asyncio from codeforces_core.account import async_login, is_user_logged_in from codeforces_core.httphelper import HttpHelper async def demo(): # http = HttpHelper(token_path='/tmp/cache_token', cookie_jar_path='/tmp/cache_cookie_jar') http = HttpHelper(token_path='', cookie_jar_path='') await http.open_session() result = await async_login(http=http, handle='<handle>', password='<password>') assert(result.success) html_data = await http.async_get('https://codeforces.com') assert(is_user_logged_in(html_data)) await http.close_session() asyncio.run(demo())
codeforces_core.contest_list module#
- async codeforces_core.contest_list.async_contest_list(http: AioHttpHelperInterface, page: int = 1, **kw) ContestList [source]
This method will use
http
for get contests page, you can both login or not login- Parameters:
page – the page in url
- Returns:
the result
Examples:
import asyncio from codeforces_core.httphelper import HttpHelper from codeforces_core.contest_list import async_contest_list async def demo(): # http = HttpHelper(token_path='/tmp/cache_token', cookie_jar_path='/tmp/cache_cookie_jar') http = HttpHelper(token_path='', cookie_jar_path='') await http.open_session() # you can login before get list result = await async_contest_list(http=http) for c in result.upcomming[:5]: print(c) for c in result.history[:5]: print(c) await http.close_session() asyncio.run(demo())
codeforces_core.contest_register module#
- async codeforces_core.contest_register.async_register(http: AioHttpHelperInterface, contest_id: str, **kw) RegisterResult [source]
This method will use
http
for register request, you need login before- Parameters:
contest_id – Codeforces contest_id in url
- Returns:
the result
Examples:
import asyncio from codeforces_core.account import async_login from codeforces_core.httphelper import HttpHelper from codeforces_core.contest_register import async_register, RegisterResultMsg async def demo(): # http = HttpHelper(token_path='/tmp/cache_token', cookie_jar_path='/tmp/cache_cookie_jar') http = HttpHelper(token_path='', cookie_jar_path='') await http.open_session() result = await async_login(http=http, handle='<handle>', password='<password>') assert(result.success) result = await async_register(http=http,contest_id='1811') print(result) # assert result.msg == RegisterResultMsg.HaveBeenRegistered # assert result.msg == RegisterResultMsg.AlreadyRegistered # assert result.msg == RegisterResultMsg.NoRegistrationIsOpenedNow await http.close_session() asyncio.run(demo())
codeforces_core.contest_meta module#
- async codeforces_core.contest_meta.async_contest_meta(http: AioHttpHelperInterface, contest_id: str, **kw) ContestPage [source]
This method will use
http
to request/contest/<contest_id>
, and parse to struct result- Parameters:
http – AioHttpHelperInterface
contest_id – contest id in url
- Returns:
parsed structured result
Examples:
import asyncio from codeforces_core.httphelper import HttpHelper from codeforces_core.contest_meta import async_contest_meta async def demo(): # http = HttpHelper(token_path='/tmp/cache_token', cookie_jar_path='/tmp/cache_cookie_jar') http = HttpHelper(token_path='', cookie_jar_path='') await http.open_session() # you can login before request result = await async_contest_meta(http=http, contest_id = '1779') print(result.id) print(result.title) print(result.url) print(result.problems) print(result.materials) await http.close_session() asyncio.run(demo())
codeforces_core.problems module#
- async codeforces_core.problems.async_problems(http: AioHttpHelperInterface, contest_id: str, **kw) List[ProblemInfo] [source]
This method will use
http
to request/contest/<contest_id>/problems
, and parse to struct result- Parameters:
http – AioHttpHelperInterface
contest_id – contest id in url
- Returns:
parsed structured result
Examples:
import asyncio from codeforces_core.httphelper import HttpHelper from codeforces_core.problems import async_problems async def demo(): # http = HttpHelper(token_path='/tmp/cache_token', cookie_jar_path='/tmp/cache_cookie_jar') http = HttpHelper(token_path='', cookie_jar_path='') await http.open_session() # you can login before request result = await async_problems(http=http, contest_id='1779') print(len(result)) print(result[0]) await http.close_session() asyncio.run(demo())
codeforces_core.problem module#
- async codeforces_core.problem.async_problem(http: AioHttpHelperInterface, contest_id: str, level: str, **kw) ParseProblemResult [source]
This method will use
http
to request/contest/<contest_id>/problems
, and parse to struct result- Parameters:
http – AioHttpHelperInterface
contest_id – contest id in url
- Returns:
parsed structured result
Examples:
import asyncio from codeforces_core.httphelper import HttpHelper from codeforces_core.problem import async_problem async def demo(): # http = HttpHelper(token_path='/tmp/cache_token', cookie_jar_path='/tmp/cache_cookie_jar') http = HttpHelper(token_path='', cookie_jar_path='') await http.open_session() # you can login before request result = await async_problem(http=http, contest_id='1779', level='F') print(result) await http.close_session() asyncio.run(demo())
codeforces_core.submit module#
- async codeforces_core.submit.async_submit(http: AioHttpHelperInterface, contest_id: str, level: str, file_path: str, lang_id: str, **kw) Tuple[str, str] [source]
This method will use
http
to post submit- Parameters:
http – AioHttpHelperInterface
ws_handler – function to handler messages
- Returns:
(submission_id, html_text of contest/<contest id>/my )
Examples:
import asyncio from codeforces_core.httphelper import HttpHelper from codeforces_core.account import async_login from codeforces_core.websocket import create_contest_ws_task from codeforces_core.submit import async_submit, display_contest_ws async def demo(): # http = HttpHelper(token_path='/tmp/cache_token', cookie_jar_path='/tmp/cache_cookie_jar') http = HttpHelper(token_path='', cookie_jar_path='') await http.open_session() result = await async_login(http=http, handle='<handle>', password='<password>') assert(result.success) print('before submit') submit_id, resp = await async_submit(http, contest_id='1777', level='F', file_path='F.cpp', lang_id='73') print('submit id:',submit_id) # connect websocket before submit sometimes cannot receive message contest_task = create_contest_ws_task(http, contest_id='1777', ws_handler=display_contest_ws) print("contest ws created"); try: result = await asyncio.wait_for(contest_task, timeout=30) print("ws is done, result:", result) except asyncio.TimeoutError: pass await http.close_session() asyncio.run(demo())
codeforces_core.websocket module#
codeforces_core.contest_standing module#
- async codeforces_core.contest_standing.async_common_standing(http: AioHttpHelperInterface, contest_id: str, page: str = '1', **kw) Standing [source]
This method will use
http
to request/contest/<contest_id>/standings/page/<page>
, and parse to struct result- Parameters:
contest_id – contest id in url
page – pagination 1-index
- Returns:
parsed structured result
Examples:
import asyncio from codeforces_core.httphelper import HttpHelper from codeforces_core.contest_standing import async_common_standing async def demo(): # http = HttpHelper(token_path='/tmp/cache_token', cookie_jar_path='/tmp/cache_cookie_jar') http = HttpHelper(token_path='', cookie_jar_path='') await http.open_session() result = await async_common_standing(http=http, contest_id='1779', page='2') print(result.head) print(len(result.rows)) print(result.rows[3]) await http.close_session() asyncio.run(demo())
- async codeforces_core.contest_standing.async_friends_standing(http: AioHttpHelperInterface, contest_id: str, **kw) Standing [source]
This method will use
http
to request/contest/<contest_id>/standings/friends/true
, and parse to struct result- Parameters:
contest_id – contest id in url
- Returns:
parsed structured result
Examples:
import asyncio from codeforces_core.account import async_login from codeforces_core.httphelper import HttpHelper from codeforces_core.contest_standing import async_friends_standing async def demo(): # http = HttpHelper(token_path='/tmp/cache_token', cookie_jar_path='/tmp/cache_cookie_jar') http = HttpHelper(token_path='', cookie_jar_path='') await http.open_session() result = await async_login(http=http, handle='<handle>', password='<password>') assert(result.success) result = await async_friends_standing(http=http, contest_id='1779') print(result.head) print(len(result.rows)) print(result.rows[3]) await http.close_session() asyncio.run(demo())
codeforces_core.language module#
- async codeforces_core.language.async_language(http: AioHttpHelperInterface, **kw) List[Lang] [source]
This method will use
http
to request/problemset/submit
, and parse language options- Returns:
parsed structured result
Examples:
import asyncio from codeforces_core.account import async_login from codeforces_core.httphelper import HttpHelper from codeforces_core.language import async_language async def demo(): # http = HttpHelper(token_path='/tmp/cache_token', cookie_jar_path='/tmp/cache_cookie_jar') http = HttpHelper(token_path='', cookie_jar_path='') await http.open_session() result = await async_login(http=http, handle='<handle>', password='<password>') assert(result.success) result = await async_language(http) for item in result: print(item) await http.close_session() asyncio.run(demo())