ParseMyCF — a codeforces contest scraper
By: Sabuj Jana
Tags: Script, Codeforces, Programming, Python, Github

I wrote an useful python script- ParseCF

It will parse all the Codeforces contests that a particular user has participated in till date, make separate folders for every contest and every folder would contain all the user’s submissions for that particular contest , ordered by the problem names.

For a guy like me who likes to keep all my codeforces submissions organised , this script saves a lot of unnecessary time in organising codes in folders .At last, I can push all my codes to Github in one click.

GOALS of this scraper:

Ask the user for the username and the number of recent contests to parse Set up a proper directory tree under the parent directory with each Folder having the (contest-name + username) format Each Folder contains all the solutions of the user having separate files for separate questions (A,B,C..) and a contest-info .txt file that encompasses all the miscellaneous details of the user w.r.t the current contest.

All the detailed instructions on how to run this script is available on my Github .

Now enough of theory ! Let me show you a demo.

Let us say I want to parse the 5 recent contests of legendary tourist i.e When the scipt will prompt me to enter a username, I’ll type in tourist

Then the scraper will

show me the total no of contests tourist has participated in till date

ask me how many recent contests I want to parse: let us say 3

As soon as I type in 3 and press Enter , the parsing will start.

To make your wait less boring, I have made the script spit out log texts as it goes on parsing contests.

Notice the parent directory has no other folder right now except cf py file right now.

Let us start the parsing.

As you can see, instantly, the folder for the first contest has been created and the log is saying the same. It is sleeping for 5s :) and then it will begin scraping the corresponding solutions for this round.

It is a coincidence that the first scraped solution of tourist is WA on pretest 10 .

Haha :)

So it continues scraping and doing it’s job. At this point, files are being added inside the first folder.

Hurray!!

The first contest(most recent one) has been parsed and it has begun scraping the second contest as you can see the folder for Manthan-Codefest has been created !

It is working hard :)

Moving on to the 3rd and the last contest for us..

Now after a lot of hard work, let us see what happens!

The above picture shows that the parsing has ended!

Now let me show you the directory structure inside each folder.

So 3 folders…

Let us enter the first folder-:

As you can see, all the problems have been scraped successfully with the proper extensions. An extra contest-info.txt file is also there. Let us explore its contents.

As you can see, it contains all miscellaneous information about the tourist’s performance in this round like Rank, Rating change etc.

Let’s go inside the 2nd one

Let’s go inside the 3rd contest folder.

So this ends the successful scraping!

Bonus:

If you place the cf py file inside a git initialised repository , it will automatically record the added files and you can just make a single commit and upload them to github.

, it will automatically record the added files and you can just You can compare the performance and code of your cf friends in the recent contests you both participated in. Just run the script again and mention your friend’s username and you’re good to go.

in the recent contests you both participated in. Just run the script again and and you’re good to go. As mentioned above , the ParseCF repository is available under my JanaSabuj/ParseMyCF-contest github. You can make improvements or put forward bugs you encounter via a pull request or fork or star.

Bonus2:

Here is a short video where I parse my favourite coder’s contests.

Username: Ashishgup

This is my first python script and I hope you will find it useful !