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://mirror.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://mirror.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.
Auto comment: topic has been updated by xalanq (previous revision, new revision, compare).
Upvoted. I must say that this is the most complete codeforces problem parser that I have seen so far.
Thanks for the effort!
Will you support Linux in the future?
He mentioned that Linux is supported.
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.
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.
Edit the file
~/.cfconfig
, and delete one 'cpp' from 'suffix'See https://github.com/xalanq/cf-tool/issues/6
Fix it in v0.5.1.
You can run
cf upgrade
to update the program.Thanks it worked.
facing the same issue 5 years later, your comment saved me LOL
Looks like a perfect match for VS Code by using only terminal command.
Yeah. The VS Code extension is in TODO list:)
any update?
So busy...sorry. I hope someone could help me :)
Awesome tool thank you very much for that!!!. I tested app previous week and everything worked fine. But now there are some problems:
cf submit
code will be submitted but status does not change it remains as "Running" and application freezes.cf race
writes "Cannot find countdown".You should upgrade the program :) glhf~
Made an upgrade:
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 appCheck your version by
cf --version
. The latest one is v0.5.4yes it works now, thank you for answer.
I can't log in though I entered my correct username and password
Try again? I made an update.
Which cf program has to put in /usr/bin?
You don't need to install it. Just copy the execution file to the
/usr/bin
. Ses FAQ #2I cannot use cf command
You can download the cf program at https://github.com/xalanq/cf-tool/releases
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!!
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 select1
. 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:
cf submit
, the tool will use the template which has the suffixpy
.cpp
and a template with aliaspy
. You can usecf gen cpp
to generate a code file with templatecpp
orcf gen py
to generate a code file with templatepy
.cf gen
).cf --help
)You can see how
before script, script, after script
works. In short, when you usecf test
, the commands will be executed in sequence:I'm sorry for my bad English. I can not express these things clearly.
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! ;)
Thanks for your feedback! I'll fix it.
I can't log in even with my correct user and password
cf --version
to check 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
Thanks for your feedback! I'll check it and make it as same as Codeforces's login.
great tool, but in login its case sensitive in username
Already fixed it in the latest version.
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
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:
If you're on Arch Linux, you can install with:
(assuming you use
yay
as your AUR helper; replace with whichever one you actually use, of course)Thank you! You could also pull a request for helping me to update the README!
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.
No, I will not provide any unfair feature :)
How to parse group contests like A2Oj ladders https://mirror.codeforces.com/group/JC4gmpF4LH/contest/259125 ?
Not yet supported
Now support gym/groups/contests/acmsguru !
This tool is simply great! It is an amazing tool :)
Thank you for the great work
how to parse only one question from problem set ?
thanks
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
Hmm..This is the text from Codeforces. I don't want to change it
hmmm but the table look weird XD, can you fix it ?
Many many thanks to you, keep up the good work <3
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?)
If you want to use some flags (e.g
-std=c++17
-Wconversion
) whenever you hitmake
without having aMakefile
, you can change~/.profile
in Linux by addingexport CXXFLAGS='-std=c++17'
. If you want to add multiple flags, append them in the same line asCXXFLAGS='-std=c++17 -Wall'
. Remember, this is considered bad practice to change the flags using environment variables.xalanq bahot hard !!
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
orcf submit c1
etc.. in the contest directory directly and the tool does the cd automatically.I can't select the language
GNU G++17 9.2.0 (64 bit, msys 2)
, there is onlyGNU G++17 7.3.0
Pls, someone help me to make template. I can't do it.
In $HOME/.cf/config there is something like:
Just enter there the path to your template file. 54 is the type for c++17.
Alternative use
cf config
and follow instructions.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://mirror.codeforces.com/blog/entry/80070. Any idea how to fix this issue?
Same issue for me when trying to login.
Yes, same, and I am fairly sure you are right, it has to do with that AES thing/bug.
This fork seems to be better cf-tool.
Your fork doesn't work for me either. Getting "Login failed. Check credentials and retry".
Awesome job man!
Someone raised an issue on GitHub, hope they will fix it asap. See here
The issue seems hard to tackle, since codeforces has added AES encryption: https://mirror.codeforces.com/blog/entry/80070.
It's can be fixed. Look at this https://github.com/meooow25/cfspy/commit/8efa2149b9f5a1e80ab7591ec938fc196d7f2fec
meooow :orz:
It doesn't support Problemset , does 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.
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?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
Thanks, Works fine...
It doesn't have C++17 (64 bits). Are you planning to add it?
So sad it doesn't support C++(64bit).
Look at this pull request
This branch seems to work fine, too. https://github.com/cp-tools/cf-tool
I want to use it .AnyBody can help me?? please
If you use linux I can help. Idk about windows.
then I have to download virtual Linux first. but how can I communicate with u[user:techiehere08]? FB or insta or something else?
You can communicate me in pm, and probably somebody else will help for windows. Don't do this virtual linux shit thing.
ok then wait for someone else.
I use it on windows together with cygwin. Just follow the installation instructions, it works pretty well.
bro, please help me .you have FB or insta?spookywooky
Your are supposed to try it on your own first. Then, when there is a problem, explain the problem. Most likely then you will get an useful hint or answer.
I install it 2 times and uninstall it bcz I could not understand the procedure.plz help me
Are you for real?
How could I help you if you do not explain the problem.
Please, accept the fork on github adding C++ 64 bit
also, which browser variable does cf race uses? it seems to ignore $BROWSER
At least it tries to use $BROWSER, see browser.go:
huh, thank you very much
I must've been doing something wrong here then
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
could you help me on how to do that?
I think it would be nice to have it somewhere other people could see too
it seems c++ 64 is very requested on the issues page
I mentioned two things. Which of the two are you asking for help on?
any of them
For building, fork https://github.com/xalanq/cf-tool/pull/104. Directions on building go binaries are in cf-tool's readme. To edit ~/.cf/config look into JSON and change the lang properties to 61.
ty very much
working as expected
I thought we would need to actually add the support for 64 but just changing the lang property indeed does the trick
V1: I use macos and it's not working
V2: Interesting, works after "source ~/.zshrc" and editing .zshrc
Please add C++17 (64 bit msys 2) submission
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.
Actually to use it you can simply put the language code into the configuration file.
In ~/.cf/config in the template definition:
"lang": "61"
thank you so much (both of you <3 ) spookywooky's solution solved my problem <3
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 :(((((((
no
https://github.com/xalanq/cf-tool/releases
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.
I uninstalled cfeditor and cf.exe files and re-installed it but still this error persists.
Please help me .
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.
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 .
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:
It seems to be
How does one find the codes for different languages? Codeforces seems to be using a new version of C++ 20.
You can inspect the html/javascript from the codeforces site.
In the drop-down menues where you choose the languages actually IDs are used.
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?Codeforces added a redirection page, which this tool cannot handle at the moment. https://github.com/xalanq/cf-tool/issues/143
Why the output i got is like this:
Get "https://mirror.codeforces.com/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.
LOL, maybe I should've searched better on CF blogs, damn. Ended up writing my own tool: https://github.com/ilidar/cf
Please add support for C++20.
Great tool :)
You can use code "73" in your configuration file without changing the programm, see https://mirror.codeforces.com/blog/entry/66552?#comment-851283
Thanks
input is wrong in new divs ... please solve it .. but really it is powerful tool thx;
It can't test problems with multiple solutions right? Also interactive problems?
I was using this even yesterday. But today I am getting
Cannot 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?I WANT TO USE THIS SOO BAD , BUT AFRAID TO USE
It fail in case:
cf race 1972B
Because the input file has HTML format. Can you fix it!https://github.com/woshiluo/cf-tool