Reminder: in case of any technical issues, you can use the lightweight website m1.codeforces.com, m2.codeforces.com, m3.codeforces.com. ×

xalanq's blog

By xalanq, 6 months ago, In English,

Codeforces Tool is a command-line interface tool for Codeforces.

It's written in golang (without any browser driver). And it's fast, small(only about 6 MB), cross-platform and powerful.

You can find the source and binary files in my git repo https://github.com/xalanq/cf-tool

You can download the tool from release page https://github.com/xalanq/cf-tool/releases

Features:

  • Support all programming languages in Codeforces.
  • Support contests and gym in Codeforces.
  • Submit codes.
  • Watch submissions' status dynamically.
  • Fetch problems' samples.
  • Build, test and run.
  • Clone all codes of someone.
  • Generate codes from the specified template (including timestamp, author, etc.)
  • List problems' stats.
  • Use default web browser to open problems' pages, standings' page, etc.
  • Colorful CLI.

I have tested the tool for contest Codeforces Round #551 (Div. 2).

It's not a cheating tool, but a tool for beautiful life :)

Pull requests are always welcome.

Examples

Examples:
  cf config            Configure the cf-tool.
  cf submit            If current path is "<contest-id>/<problem-id>", cf will find the
                       code which can be submitted. Then submit to <contest-id> <problem-id>.
  cf submit a.cpp
  cf submit 100 a
  cf submit 100 a a.cpp
  cf list              List all problems' stats of a contest.
  cf list 1119
  cf parse 100         Fetch all problems' samples of contest 100 into "./100/<problem-id>".
  cf parse 100 a       Fetch samples of problem "a" of contest 100 into "./100/a".
  cf parse             Fetch samples of current problem into current path.
  cf gen               Generate a code from default template.
  cf gen cpp           Generate a code from the template whose alias is "cpp" into current path.
  cf test              Run the commands of a template in current path. Then test all samples.
                       If you want to add a new testcase, create two files "inK.txt" and "ansK.txt"
                       where K is a string with 0~9.
  cf watch             Watch the first 10 submissions of current contest.
  cf watch all         Watch all submissions of current contest.
  cf open 1136 a       Use default web browser to open the page of contest 1136, problem a.
  cf open 1136         Use default web browser to open the page of contest 1136.
  cf stand             Use default web browser to open the standing page.
  cf sid 52531875      Use default web browser to open the submission 52531875's page.
  cf sid               Open the last submission's page.
  cf race 1136         If the contest 1136 has not started yet, it will countdown. When the
                       countdown ends, it will open all problems' pages and parse samples.
  cf pull 100          Pull all problems' latest codes of contest 100 into "./100/<problem-id>".
  cf pull 100 a        Pull the latest code of problem "a" of contest 100 into "./100/<problem-id>".
  cf pull ac 100 a     Pull the "Accepted" or "Pretests passed" code of problem "a" of contest 100.
  cf pull              Pull the latest code of current problem into current path.
  cf clone xalanq      Clone all codes of xalanq.
  cf upgrade           Upgrade the "cf" to the latest version from GitHub.

You should run cf config to configure your username, password and template at first.

Let's simulate a competition.

cf race 1136

To start competing the contest 1136! The id 1136 can be found in the contest URL.

e.g. https://codeforces.com/contest/1136

If the contest has not started yet, cf will count down. If the contest have started or the countdown ends, cf will use the default browser to open all problems' page and fetch all samples to the local.

cd 1136/a

Enter the directory of problem A, the directory should contain all samples of the problem.

cf gen

Generate a code with the default template. The filename of the code is problem id by default.

vim a.cpp

Use Vim to write the code (It depends on yourself).

cf test

Compile and test all samples.

cf submit

Submit the code.

cf list

List problems' stats of the contest.

cf stand

Open the standings' page of the contest.

FAQ

I double click the program but it doesn't work

Codeforces Tool is a command-line tool. You should run it in terminal.

I cannot use cf command

You should put the cf program to a path (e.g. /usr/bin/ in Linux) which has been added to system environment variable PATH.

Or just google "how to add a path to system environment variable PATH".

How to add a new testcase

Create two extra testcase files inK.txt and ansK.txt (K is a string with 0~9).

Enable tab completion in terminal

Use this Infinidat/infi.docopt_completion.

Note: If there is a new version released (especially a new command added), you should run docopt-completion cf again.

 
 
 
 
  • Vote: I like it
  • +276
  • Vote: I do not like it

»
6 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by xalanq (previous revision, new revision, compare).

»
6 months ago, # |
Rev. 2   Vote: I like it +52 Vote: I do not like it

Upvoted. I must say that this is the most complete codeforces problem parser that I have seen so far.

Thanks for the effort!

»
6 months ago, # |
  Vote: I like it -8 Vote: I do not like it

Will you support Linux in the future?

  • »
    »
    6 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    He mentioned that Linux is supported.

»
6 months ago, # |
  Vote: I like it +13 Vote: I do not like it

Yeah. Right. csrf / evercookie extraction.

Good thing that Mike never bothered to provide good api and forces people to scrape pages if you plan doing anything cf related ever.

»
5 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it
There are multiple language match the file.
  0: GNU G++11 5.1.0
  1: GNU G++11 5.1.0
Please choose one(index):

It is saying me something like this whenever I am trying to test or submit . Is there any way I can change the config so that it doesn't ask me for the option.

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Looks like a perfect match for VS Code by using only terminal command.

»
4 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Awesome tool thank you very much for that!!!. I tested app previous week and everything worked fine. But now there are some problems:

  1. After command cf submit code will be submitted but status does not change it remains as "Running" and application freezes.
  2. After command cf race writes "Cannot find countdown".
  • »
    »
    4 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    You should upgrade the program :) glhf~

    • »
      »
      »
      4 months ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      Made an upgrade:

      1. Status does not change, but Ctrl + C can kill process. I think if status does not change in console automatically then this application is inconvenient to use, better send it through browser, because we do almost same actions in case we use app and in case we do not use app
      2. not fixed
      • »
        »
        »
        »
        4 months ago, # ^ |
        Rev. 2   Vote: I like it +3 Vote: I do not like it

        Check your version by cf --version. The latest one is v0.5.4

        1. It works for me. I just tried to submit in 5 minutes ago. May be you should wait some seconds after submitting?
        2. It doesn't work for the contest Codeforces Round #567 (Div. 2) with 5 days countdown (I don't think this is a very bad problem, maybe I'll fix it later), but it works for me in a virtual contest Codeforces Round #564 (Div. 1) with a 5 minutes countdown.
»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I can't log in though I entered my correct username and password

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Which cf program has to put in /usr/bin?

»
4 weeks ago, # |
Rev. 3   Vote: I like it +2 Vote: I do not like it

Can anyone explain me the use of template and how does it work and why is it required?

For eg: if my code is written in 123.cpp and i want to compile it then i use:

g++ -o 123 123.cpp // a binary file is created with name 123 corresponding to my code.

Now when i submit it using : cf submit contest-id problem-id 123.cpp How does the template work( suffix, alias, before script, script, after script, path).

Is it necessary to write my code in the same path as entered in template?

Thanks in advance!!

  • »
    »
    4 weeks ago, # ^ |
    Rev. 5   Vote: I like it +1 Vote: I do not like it

    There are 2 template types: Code template and script template.

    The script template contains the language you use (e.g. cpp, python, java), the path of code template and some extra info. You cannot submit your code before configuring the script template. You can add a script template by cf config and then select 1. There will be some hints guiding you to configure the template.

    The code template just a code file, you can generate a code file from this template by cf gen.

    You said you want to compile the code, so you should focus on the script template.

    There are some concepts in script template:

    • suffix means the template will be used by detecting the suffix of the submitting or testing code file. E.g. you have a file in current path: a.py. Then you use cf submit, the tool will use the template which has the suffix py.
    • alias means an alias for the template. E.g. you have a template with alias cpp and a template with alias py. You can use cf gen cpp to generate a code file with template cpp or cf gen py to generate a code file with template py.
    • Template absolute path means the code template's path (using it in cf gen).
    • before script, script, after script: In usage (You can see it by cf --help)
    Script in template:
      Template will run 3 scripts in sequence when you run "cf test":
        — before_script   (execute once)
        — script          (execute the number of samples times)
        — after_script    (execute once)
      You could set "before_script" or "after_script" to empty string, meaning not executing.
      You have to run your program in "script" with standard input/output (no need to redirect).
    
      You can insert some placeholders in your scripts. When execute a script,
    

    You can see how before script, script, after script works. In short, when you use cf test, the commands will be executed in sequence:

    • before_script
    • script
    • after_script

    I'm sorry for my bad English. I can not express these things clearly.

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      Thanks a lot. It was really helpful!!.

      One more thing that I noticed ( probably a bug ; not sure ) is that whenever we try to issue multiple commands of cf open using different contest-ids, it opens the contest page of first command issued .

      Eg : cf open 100 (contest page for contest id 100 opens) cf open 200 (contest page for contest id 100 opens) cf open 300 (contest page for contest id 100 opens)

      Although this issue is not experienced while specifying problem-id.

      Eg: cf open 100 a (problem page for 100 a opens) cf open 200 b (problem page for 200 b opens) cf open 300 c (problem page for 300 c opens)

      Hope this might be useful for next version! ;)

      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thanks for your feedback! I'll fix it.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I can't log in even with my correct user and password

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    1. Is it the latest version v0.8.2? You can use cf --version to check it.
    2. The password could be hidden, don't add any other characters in your password.
    3. According to the comment above, you could make an case sensitive error.
    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes, it's the latest version. And I didn't make any case sensitive error, I even tried to change my password twice. :(

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      nevermind, I thought you were talking about password case sensitive error, but you need to type the user handle exactly as it shows in CF, my bad. I tried with my e-mail as well and I was unable to log in

      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thanks for your feedback! I'll check it and make it as same as Codeforces's login.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

great tool, but in login its case sensitive in username

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Why there have "exec: "ok": executable file not found in %PATH%" when I use "cf test" in Windows (32 bit)? My version is v0.8.2