def main(prog, args, output_file=sys.stdout): parser = argparse.ArgumentParser( prog=prog, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( "url", help="URL (e.g. https://atcoder.jp/contests/abc012/tasks/abc012_3)") parser.add_argument("--without-login", action="store_true", help="Download data without login") parser.add_argument( "--lang", help="Programming language of your template code, {}.\n".format( " or ".join([lang.name for lang in ALL_LANGUAGES])) + "[Default] {}".format(CPP.name)) parser.add_argument("--template", help="File path to your template code\n{}".format( "\n".join([ "[Default ({dname})] {path}".format( dname=lang.display_name, path=lang.default_template_path) for lang in ALL_LANGUAGES ]))) parser.add_argument("--save-no-session-cache", action="store_true", help="Save no session cache to avoid security risk", default=None) parser.add_argument( "--config", help="File path to your config file\n{0}{1}".format( "[Default (Primary)] {}\n".format(USER_CONFIG_PATH), "[Default (Secondary)] {}\n".format(get_default_config_path()))) args = parser.parse_args(args) args.workspace = DEFAULT_WORKSPACE_DIR_PATH # dummy for get_config() args.parallel = False # dummy for get_config() config = get_config(args) client = AtCoderClient() if not config.etc_config.download_without_login: try: client.login( save_session_cache=not config.etc_config.save_no_session_cache) logging.info("Login successful.") except LoginError: logging.error( "Failed to login (maybe due to wrong username/password combination?)" ) sys.exit(-1) else: logging.info("Downloading data without login.") generate_code(client, args.url, config, output_file=output_file)
def test_backup(self): answer_data_dir_path = os.path.join(RESOURCE_DIR, "test_backup") # Prepare workspace twice for _ in range(2): prepare_contest( AtCoderClient(), "agc029", Config(code_style_config=CodeStyleConfig( workspace_dir=self.temp_dir, template_file=TEMPLATE_PATH, lang="cpp", ))) self.assertDirectoriesEqual(answer_data_dir_path, self.temp_dir)
def main(lang='ja'): alphabet = str(Path('.').absolute().name) contest_id = str(Path('.').absolute().parent.name) client = AtCoderClient() client.login() ic(client.check_logging_in()) contest = Contest(ic(contest_id)) ic(contest.get_url()) problem_list = client.download_problem_list(ic(contest)) problem = problem_list[['A', 'B', 'C', 'D', 'E', 'F'].index(ic(alphabet))] html_doc = client.download_problem_content(problem).original_html soup = BeautifulSoup(html_doc, 'html.parser') title = soup.find(class_="h2").get_text() task_statement = soup.find(id="task-statement") if lang == 'ja': task_statement = task_statement.find(class_='lang-ja') def sanitize_html_for_ipynb(html_doc): replace_dict = { '<var>': '$', '</var>': '$', '<pre>': '<pre><code>', '</pre>': '</code></pre>' } for old_word, new_word in replace_dict.items(): html_doc = html_doc.replace(old_word, new_word) return ic(html_doc) title = str(sanitize_html_for_ipynb(str(title))) title = title.lstrip().split('\n')[0] task_statement = Tomd(sanitize_html_for_ipynb(str(task_statement))) with open('problem.md', 'w+') as f: f.write(f"## {ic(title)}\n") f.write('---\n') f.write(task_statement.markdown)
#!/usr/bin/env python3 from atcodertools.client.models.contest import Contest from atcodertools.client.atcoder import AtCoderClient import sys # write contest id here cid = sys.argv[1] print('Contest ID = {}'.format(cid)) try: at = AtCoderClient() at.login() cn = Contest(cid) pls = at.download_problem_list(cn) except Exception as e: print('ログイン/問題取得でエラー Exception = {}'.format(e)) else: from subprocess import run from glob import glob run(['rm', '-r', 'tests']) run(['mkdir', 'tests']) for pl in pls: k = pl.alphabet v = pl.get_url() try:
def main(prog, args, credential_supplier=None, use_local_session_cache=True) -> bool: parser = argparse.ArgumentParser( prog=prog, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( "--exec", '-e', help= "File path to the execution target. [Default] Automatically detected exec file", default=None) parser.add_argument( "--dir", '-d', help="Target directory to test. [Default] Current directory", default=".") parser.add_argument("--timeout", '-t', help="Timeout for each test cases (sec) [Default] 1", type=int, default=1) parser.add_argument( "--code", '-c', help= "Path to the source code to submit [Default] Code path written in metadata.json", type=str, default=None) parser.add_argument( "--force", "-f", action="store_true", help= "Submit the code regardless of the local test result [Default] False", default=False) parser.add_argument("--save-no-session-cache", action="store_true", help="Save no session cache to avoid security risk", default=False) parser.add_argument( "--unlock-safety", "-u", action="store_true", help= "By default, this script only submits the first code per problem. However, you can remove" " the safety by this option in order to submit codes twice or more.", default=False) args = parser.parse_args(args) metadata_file = os.path.join(args.dir, "metadata.json") try: metadata = Metadata.load_from(metadata_file) except IOError: logger.error( "{0} is not found! You need {0} to use this submission functionality." .format(metadata_file)) return False try: client = AtCoderClient() client.login( save_session_cache=args.save_no_session_cache, credential_supplier=credential_supplier, use_local_session_cache=use_local_session_cache, ) except LoginError: logger.error("Login failed. Try again.") return False tester_args = [] if args.exec: tester_args += ["-e", args.exec] if args.dir: tester_args += ["-d", args.dir] if args.timeout: tester_args += ["-t", str(args.timeout)] if args.force or tester.main("", tester_args): submissions = client.download_submission_list(metadata.problem.contest) if not args.unlock_safety: for submission in submissions: if submission.problem_id == metadata.problem.problem_id: logger.error( with_color( "Cancel submitting because you already sent some code to the problem. Please " "specify -u to send the code. {}".format( metadata.problem.contest.get_submissions_url( submission)), Fore.LIGHTRED_EX)) return False code_path = args.code or os.path.join(args.dir, metadata.code_filename) with open(code_path, 'r') as f: source = f.read() logger.info("Submitting {} as {}".format(code_path, metadata.lang.name)) submission = client.submit_source_code(metadata.problem.contest, metadata.problem, metadata.lang, source) logger.info("{} {}".format( with_color("Done!", Fore.LIGHTGREEN_EX), metadata.problem.contest.get_submissions_url(submission)))
def setUp(self): self.temp_dir = tempfile.mkdtemp() self.client = AtCoderClient()
#!/usr/bin/python3 # -*- coding: utf-8 -*- import errno import os from atcodertools.client.atcoder import AtCoderClient class NoPatternFoundError(Exception): pass atcoder = AtCoderClient() def mkdirs(path): try: os.makedirs(path) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(path): pass if __name__ == "__main__": htmls_dir = "./problem_htmls/" mkdirs(htmls_dir) for contest in atcoder.download_all_contests(): for problem in atcoder.download_problem_list(contest): html_path = os.path.join( htmls_dir, "{contest}-{problem_id}.html".format( contest=contest.get_id(),
def main(prog, args): parser = argparse.ArgumentParser( prog=prog, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument("contest_id", help="Contest ID (e.g. arc001)") parser.add_argument("--without-login", action="store_true", help="Download data without login") parser.add_argument( "--workspace", help="Path to workspace's root directory. This script will create files" " in {{WORKSPACE}}/{{contest_name}}/{{alphabet}}/ e.g. ./your-workspace/arc001/A/\n" "[Default] {}".format(DEFAULT_WORKSPACE_DIR_PATH)) parser.add_argument( "--lang", help="Programming language of your template code, {}.\n".format( " or ".join([lang.name for lang in ALL_LANGUAGES])) + "[Default] {}".format(CPP.name)) parser.add_argument("--template", help="File path to your template code\n{}".format( "\n".join([ "[Default ({dname})] {path}".format( dname=lang.display_name, path=lang.default_template_path) for lang in ALL_LANGUAGES ]))) # Deleted functionality parser.add_argument('--replacement', help=argparse.SUPPRESS) parser.add_argument( "--parallel", action="store_true", help= "Prepare problem directories asynchronously using multi processors.", default=None) parser.add_argument("--save-no-session-cache", action="store_true", help="Save no session cache to avoid security risk", default=None) parser.add_argument( "--config", help="File path to your config file\n{0}{1}".format( "[Default (Primary)] {}\n".format(USER_CONFIG_PATH), "[Default (Secondary)] {}\n".format(get_default_config_path()))) args = parser.parse_args(args) if args.replacement is not None: logger.error( with_color( "Sorry! --replacement argument no longer exists" " and you can only use --template." " See the official document for details.", Fore.LIGHTRED_EX)) raise DeletedFunctionalityError config = get_config(args) try: import AccountInformation # noqa raise BannedFileDetectedError( "We abolished the logic with AccountInformation.py. Please delete the file." ) except ImportError: pass client = AtCoderClient() if not config.etc_config.download_without_login: try: client.login( save_session_cache=not config.etc_config.save_no_session_cache) logger.info("Login successful.") except LoginError: logger.error( "Failed to login (maybe due to wrong username/password combination?)" ) sys.exit(-1) else: logger.info("Downloading data without login.") prepare_contest(client, args.contest_id, config)
def test_decorated(*args, **kwargs): client = AtCoderClient() prev = client._request func(*args, **kwargs) client._request = prev