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.
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.
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 :)
ok no problem
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.
I didn't noticed it was case sensitive.
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
It says permission denied when i try to move it to /usr/bin even when i have allowed the execution as a program
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 fileexport PATH="/home/$USER/bin:$PATH"
.I actually got it by using sudo and then pasting in /usr/bin
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.
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
(whereinvalidproblemid
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, andcf open
with path.../100
will open 100.Hey xalanq, I am unable to create my own template. What do we add in script? An example will work.
I can't log in even with my correct user and password
cf --version
to check it.Yes, it's the latest version. And I didn't make any case sensitive error, I even tried to change my password twice. :(
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 :)
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!
How to parse group contests like A2Oj ladders https://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 add before script,script and after script for java?
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
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?
I handled it!
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.how to use it with interactive problems? or could we use it at all?
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?
Same issue for me when trying to login.
Same thing for me as well.
Yes, same, and I am fairly sure you are right, it has to do with that AES thing/bug.
Same issue, hope it gets fixed.
Maybe, nows the right time to switch to my fork of the project cf-tool. A much bigger project (supporting all major websites) is on WIP tho...
Your fork doesn't work for me either. Getting "Login failed. Check credentials and retry".
Your version looks amazing, which other websites do you plan to extend it to, or have already extended to?
UPD: I am also getting the same result described by h2o_ that says
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://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?
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.
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.
Yeah me too acing the same issue cannot find csrf
link https://ibb.co/RPbfZp4
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?
I have named my script file as
dummy
and getting the following message after running the commandcf test
: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.
at first tell me all softwares names?
Thanks!! I have added this little function to my .zshrc file which will automate the process of generating the templates and opening the cpp files into vim (I am using MacVim)
All you need now is type race 'contestid' and start solving the problems. thanks again!
Command — (cf gen) is not working its saying add a new template. I am using linux. If anyone can help. Thanks!
Upd: Now its working thanks xalanq for this awesome tool.