xalanq's blog

By xalanq, 18 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 7 MB), cross-platform(Windows, macOS, Linux) 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 Contests, Gym, Groups and acmsguru.
  • Support all programming languages in Codeforces.
  • Submit codes.
  • Watch submissions' status dynamically.
  • Fetch problems' samples.
  • Compile and test locally.
  • Clone all codes of someone.
  • Generate codes from the specified template (including timestamp, author, etc.)
  • List problems' stats of one contest.
  • Use default web browser to open problems' pages, standings' page, etc.
  • Setup a network proxy. Setup a mirror host.
  • 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            cf will detect what you want to submit automatically.
  cf submit -f a.cpp
  cf submit https://codeforces.com/contest/100/A
  cf submit -f a.cpp 100A 
  cf submit -f a.cpp 100 a
  cf submit contest 100 a
  cf submit gym 100001 a
  cf list              List all problems' stats of a contest.
  cf list 1119
  cf parse 100         Fetch all problems' samples of contest 100 into
                       "{cf}/{contest}/100/".
  cf parse gym 100001a
                       Fetch samples of problem "a" of gym 100001 into
                       "{cf}/{gym}/100001/a".
  cf parse gym 100001
                       Fetch all problems' samples of gym 100001 into
                       "{cf}/{gym}/100001".
  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 1136a        Use default web browser to open the page of contest
                       1136, problem a.
  cf open gym 100136   Use default web browser to open the page of gym
                       100136.
  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 codes 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.

Let's simulate a competition.

cf race 1136 or cf race https://codeforces.com/contest/1136

To start competing the 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 dashboard's page and problems' page, and fetch all samples to the local.

cd ./cf/contest/1136/a (May be different from this, please notice the message on your screen)

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

»
18 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).

»
18 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!

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

Will you support Linux in the future?

»
18 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.

»
18 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.

»
18 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.

»
17 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".
  • »
    »
    17 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    You should upgrade the program :) glhf~

    • »
      »
      »
      17 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
      • »
        »
        »
        »
        17 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.
»
17 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

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

    Try again? I made an update.

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

      I didn't noticed it was case sensitive.

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

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

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

    You don't need to install it. Just copy the execution file to the /usr/bin. Ses FAQ #2 I cannot use cf command

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

      It says permission denied when i try to move it to /usr/bin even when i have allowed the execution as a program

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

        go to your home directory and create a new folder called bin. Now paste the tool in that folder. Now open up the terminal and type gedit ~/.bashrc and add this statement at the end of the file export PATH="/home/$USER/bin:$PATH".

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

          I actually got it by using sudo and then pasting in /usr/bin

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

    You can download the cf program at https://github.com/xalanq/cf-tool/releases

»
13 months 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!!

  • »
    »
    13 months 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.

    • »
      »
      »
      13 months 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! ;)

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

        Thanks for your feedback! I'll fix it.

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

          This is because when the contest-id is specified but not the problem-id, the problem id will be the folder name, so the page codeforces.com/contest/200/problem/invalidproblemid (where invalidproblemid is your folder name) will be opened, which will redirect to your last visited page.

          That behavior is intended in case you run cf open with path .../100/a it will open 100A, and cf open with path .../100 will open 100.

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

      Hey xalanq, I am unable to create my own template. What do we add in script? An example will work.

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

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

  • »
    »
    13 months 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.
    • »
      »
      »
      13 months 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. :(

    • »
      »
      »
      13 months 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

      • »
        »
        »
        »
        13 months 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.

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

great tool, but in login its case sensitive in username

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

    Already fixed it in the latest version.

»
13 months 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

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

I've packaged cf-tool for both Homebrew (on Mac) and AUR (for Arch Linux).

If you're on a Mac, you can install just by doing:

brew install cf-tool

If you're on Arch Linux, you can install with:

yay -S cf-tool

(assuming you use yay as your AUR helper; replace with whichever one you actually use, of course)

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

    Thank you! You could also pull a request for helping me to update the README!

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

Hey! Amazing tool. Can you add the feature to pull all submissions(i.e other's solutions as well) for a particular problem. Would be useful for hacking.

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

    No, I will not provide any unfair feature :)

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

Just a recommendation to add to the documentation, for I had some troubles trying to get the command to work. After a lot of work, I finally found that the file did not have execute permissions. Maybe adding a line to the doc saying 'Permission denied' to not use sudo but run 'sudo chmod a+x cf' with the file name. Could save a lot of trouble for those that come after me.

Thanks for the tool! Now that I got it working I'm loving it!

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

How to parse group contests like A2Oj ladders https://codeforces.com/group/JC4gmpF4LH/contest/259125 ?

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

This tool is simply great! It is an amazing tool :)

Thank you for the great work

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

How to add before script,script and after script for java?

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

how to parse only one question from problem set ?

»
9 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Sometimes it's length is so large that the table is separate into 2 lines. How can I change "Time limit exceeded on pretest XXX" -> "TLE on pretest XXX" so that the table wont break into 2 part ?

Sorry for my bad English

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

    Hmm..This is the text from Codeforces. I don't want to change it

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

      hmmm but the table look weird XD, can you fix it ?

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

Many many thanks to you, keep up the good work <3

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

Great tool!
Is there a possibility to automatically add a makefile in the problem folder by cf gen in addition to the used template file? (Maybe by some before_script for cf gen?)

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

    If you want to use some flags (e.g -std=c++17 -Wconversion) whenever you hit make without having a Makefile, you can change ~/.profile in Linux by adding export CXXFLAGS='-std=c++17'. If you want to add multiple flags, append them in the same line as CXXFLAGS='-std=c++17 -Wall'. Remember, this is considered bad practice to change the flags using environment variables.

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

xalanq bahot hard !!

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

Would be amazing if you could add support to specify problem to commands "test" and "submit" as right now I have to cd into problem directory in order to do this commands and then cd back into contest and cd into another problem etc... which is just a hassle.

TLDR: We should be able to do cf test a or cf submit c1 etc.. in the contest directory directly and the tool does the cd automatically.

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

I can't select the language GNU G++17 9.2.0 (64 bit, msys 2), there is only GNU G++17 7.3.0

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

Hi!

I started to use cf tool. I am trying to add current time and date to my code but I couldn't. Can you pls help me about it?

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

Pls, someone help me to make template. I can't do it.

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

    In $HOME/.cf/config there is something like:

      "template": [
        {
          "alias": "cpp",
          "lang": "54",
          "path": "C:\\cygwin64\\home\\fendriss\\git\\ktlnutl\\src\\main\\cc\\T.cc",
          "suffix": [
            "cc"
          ],
    

    Just enter there the path to your template file. 54 is the type for c++17.

    Alternative use cf config and follow instructions.

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

how to use it with interactive problems? or could we use it at all?

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

CF Tool has abruptly stopped working for me. It throws "Cannot find csrf" error while logging in. It may have something to do with the problem described in this blog https://codeforces.com/blog/entry/80070. Any idea how to fix this issue?

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

It doesn't support Problemset , does it?

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

When I run cf test inside the problem folder ../1380/a I get the following error:

Runtime Error #1 ... exec: "./a.exe": file does not exist

My a.cpp file is present inside the ../1380/a folder along with the test cases files.

Please help me to resolve this issue.

»
3 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Great tool, I love it!

I'm getting an error now when I'm trying to submit problems (this didn't happen before). When I try to log in it gives me:

Login skittles1412... Cannot find csrf

I'm sure that I have entered my username and password correctly. What can I try? Thanks in advance.

UPD: It seems that this is a CodeForces issue. See here and here. online-judge-tools is also not working. Could this probably be a hint of a potential server failiure? MikeMirzayanov please look into this.

UPD: Issue has been fixed.

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

After entering command cf test, it shows failed test cases and even the outputs are wrong, inspite my code being correct(tested from cf). I use g++ -o [dollar]%file%[dollar] [dollar]%full%[dollar] -std=c++17 in both my before script and script. What is going wrong?

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

    I use g++ -o [dollar]%file%[dollar] [dollar]%full%[dollar] -std=c++17, this is before script. In script, use "./[dollar]%file%[dollar]" to run program

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

It doesn't have C++17 (64 bits). Are you planning to add it?

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

I have named my script file as dummy and getting the following message after running the command cf test:

C:\Users\Badal Yadav\cf\contest\1186\a>cf test
Runtime Error #1 ... exec: "dummy": executable file not found in %PATH%
Runtime Error #2 ... exec: "dummy": executable file not found in %PATH%
Runtime Error #3 ... exec: "dummy": executable file not found in %PATH%