Блог пользователя xalanq

Автор xalanq, 6 лет назад, По-английски

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.net/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.net/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.

  • Проголосовать: нравится
  • +276
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +52 Проголосовать: не нравится

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

Thanks for the effort!

»
6 лет назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

Will you support Linux in the future?

»
6 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

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.

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
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.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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".
  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    You should upgrade the program :) glhf~

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      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
      • »
        »
        »
        »
        5 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

        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.
»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
Rev. 3   Проголосовать: нравится +2 Проголосовать: не нравится

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

  • »
    »
    5 лет назад, # ^ |
    Rev. 5   Проголосовать: нравится +1 Проголосовать: не нравится

    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.

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      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! ;)

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    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.
    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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

      • »
        »
        »
        »
        5 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

great tool, but in login its case sensitive in username

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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)

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

Thank you for the great work

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

how to parse only one question from problem set ?

»
5 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

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?)

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
5 лет назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

xalanq bahot hard !!

»
5 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.net/blog/entry/80070. Any idea how to fix this issue?

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

It doesn't support Problemset , does it?

»
4 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

So sad it doesn't support C++(64bit).

»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

I want to use it .AnyBody can help me?? please

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Please, accept the fork on github adding C++ 64 bit

also, which browser variable does cf race uses? it seems to ignore $BROWSER

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    At least it tries to use $BROWSER, see browser.go:

    // Commands returns a list of possible commands to use to open a url.
    func Commands() [][]string {
            var cmds [][]string
            if exe := os.Getenv("BROWSER"); exe != "" {
                    cmds = append(cmds, []string{exe})
            }
    
    
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    xalanq has been pretty inactive, and the pr has been there for a long time so I doubt it'll be merged anytime soon. You can build the binaries yourself or write a script to edit ~/.cf/config

»
4 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

V1: I use macos and it's not working

V2: Interesting, works after "source ~/.zshrc" and editing .zshrc

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Please add C++17 (64 bit msys 2) submission

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    If you are building cf-tools yourself, clone https://github.com/igoose1/cf-tool. It's a fork I've made right now which does almost nothing but adds C++ 17, Ruby 3, C# 8 and updates old languages.

    I got very late that the last commit from xalanq had been a year ago.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Actually to use it you can simply put the language code into the configuration file.

    In ~/.cf/config in the template definition:

    "lang": "61"

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      thank you so much (both of you <3 ) spookywooky's solution solved my problem <3

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

hey guy, how to use it on windows ?? i have been dowload cf-tool but i don't known how to use it pls help me :(((((((

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

xalanq

I was changing the path of the files to be stored. But when i was pasting the path i accidentally pasted one contest link and pressed ENTER.

It is showing like this.


panic: regexp: Compile(`D:\Competitive Programming\codeforces/https://codeforces.net/contest/988/((?P<contestID>\d+)/((?P<problemID>\w+)/)?)?`): error parsing regexp: invalid escape sequence: `\C` goroutine 1 [running]: regexp.MustCompile(0xc000126380, 0x75, 0xc000107c38) /usr/local/go/src/regexp/regexp.go:311 +0x159 github.com/xalanq/cf-tool/cmd.parsePath(0xc0001ce4c0, 0x1c, 0x7bb84a) /Users/xalanq/go/src/github.com/xalanq/cf-tool/cmd/args.go:225 +0x2c7 github.com/xalanq/cf-tool/cmd.parseArgs(0xc000177bc0, 0x7375e0, 0xc0001dc340) /Users/xalanq/go/src/github.com/xalanq/cf-tool/cmd/args.go:93 +0x8f0 github.com/xalanq/cf-tool/cmd.Eval(0xc000177bc0, 0x27, 0xc0001ce1a0) /Users/xalanq/go/src/github.com/xalanq/cf-tool/cmd/cmd.go:23 +0x7e main.main() /Users/xalanq/go/src/github.com/xalanq/cf-tool/cf.go:160 +0x2d1

I uninstalled cfeditor and cf.exe files and re-installed it but still this error persists.

Please help me .

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    In your home directory you will find a directory and file ~/.cf/config

    You can edit that by hand to get rid of the above error, or simply remove the directory to reset all previously stored data.

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Thanks a lot.. it's resolved. I deleted many files and those files name were also cp .

      I didn't spot a file with .cp initially .

      Anyway thanks .

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Since now c++20 is available, does anybody know which number code to use in the cf config file?

These are the codes for the older c++ versions:

   45: GNU C++11 5 ZIP
   42: GNU G++11 5.1.0
   50: GNU G++14 6.4.0
   54: GNU G++17 7.3.0
   61: GNU G++17 9.2.0 (64 bit)
   43: GNU GCC C11 5.1.0
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    It seems to be

    <option value="73">GNU G++20 11.2.0 (64 bit, winlibs)</option>
    
    • »
      »
      »
      8 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      How does one find the codes for different languages? Codeforces seems to be using a new version of C++ 20.

      • »
        »
        »
        »
        7 месяцев назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        You can inspect the html/javascript from the codeforces site.

        In the drop-down menues where you choose the languages actually IDs are used.

»
3 года назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Since the end of the CF round yesterday, I have not been able to log in using cf-tool. It keeps returning Cannot find csrf. Does anyone know what happened and how to fix it?

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Why the output i got is like this:

Get "https://codeforces.net/enter": dial tcp 213.248.110.126:443: connectex: An attempt was made to access a socket in a way forbidden by its access permissions.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

LOL, maybe I should've searched better on CF blogs, damn. Ended up writing my own tool: https://github.com/ilidar/cf

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Please add support for C++20.

Great tool :)

»
2 года назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

input is wrong in new divs ... please solve it .. but really it is powerful tool thx;

»
2 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

It can't test problems with multiple solutions right? Also interactive problems?

»
2 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

I was using this even yesterday. But today I am gettingCannot find csrf while logging in. Anyone facing this has resolved this? I have checked this, but no use. Something I got to know about the issue (by going through some blogs on it in CF) is that this is perhaps due to redirecting issue. But don't know how to resolve. Can anyone help me?

»
10 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I WANT TO USE THIS SOO BAD , BUT AFRAID TO USE

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

It fail in case: cf race 1972B Because the input file has HTML format. Can you fix it!