Return to Blog Home

Automated Codewars Solution Rating

Source 

Automated Codewars Solution Rating

Think of all the free honor you're missing...about to reclaim all that missing honor!

If you didn't know, rating a Kata after you've solved it gives you an extra honor, therefore some people could be missing as many solutions as they've done honor!

It took little modification for my script to determine the vote status, as I am already scraping the JSON-encoded information on each page, all I needed to do was access the vote status - -1, 0, 1, or null - from the data and save it with the solution information.

Then I attempted to do what I've already been doing - using the user tokens to make the requests to codewars the same as the browser. Unfortunately codewars uses CSRF tokens to mitigate such attempts, and even when parsing the CSRF token from the HTML, I was still missing something that made them work.


So I decided to split this feature into two parts, one to list all the unrated katas, and one to actually automate the rating of selected katas.

Playwright

This led me to using Playwright - it was already installed in the project for fetching user credentials - to navigate to each unrated katas page, rate as the user has requested, and update the vote in the local data.

Thankfully this was not tedious to do, I copied my existing login code from the previous script, visited each URL, opened the solutions tab, and finally clicked on the vote button with the appropriate <li data-value> attribute.

Future

Eventually I would add further customization - the ability to select which vote to change each kata to, an estimateion of how long this would take, and more quality of life features.