/drivetest-ca-availabilities

My attempt on trying to see which dates are available for driving test centers around Ontario

Primary LanguagePython

drivetest-ca-availabilities

This is my attempt on trying to see which dates are available for driving test centers around Ontario. My inspiration was that I needed to book my G test in August, but since it was a busy time it was hard to find a testing center in or near the GTA. Since there wasn't an option to filter for places based on availability between dates, I had decided to reverse-engineer the API and try to find that information myself.

Since the website was made in AngularJS, there were REST calls with JSON responses made which was easy to spot with the Chrome developer tools. I had found the endpoint that contained all the test centers, and the endpoint to check the availability of each test center for a specific month. Using the endpoint that returned all the test centers, I saved the ones that did G tests by saving their service ID and the city name into an array of tuplets. Then, I used the endpoint to check the availability of each test center for a specific month for each driving center that I found.

However, there was an authentication guard on that endpoint so I had to reverse-engineer the login endpoint. I found that the login endpoint required an email, a confirmation of it (for some reason...), my driver licence number, the expiry date and a ReCaptcha code. The first 4 were pretty easy to enter but the ReCaptcha code was going to be a bit tricky. I didn't want to overcomplicate the script by adding something like Selenium and OpenCV just so I could bypass ReCaptcha. I noticed that when ReCaptcha had confirmed I was not a robot, it sent a callback to the website with a code which looked exactly like the one being passed inside the endpoint, so I decided to just do this part manually. I decided to test this with Postman but when I sent the request, I got a response with a 500 status code. I figured maybe I had forgotten to add something like an Authorization header but the only thing I could find were 3 cookies that may have been connected to how the website does authorization. I tried a bunch of requests with a combination of each cookie but I kept receiving status code 500 for each request, which is where I gave up. Since I wasn't sure how the website generated the session ID or the dmid cookie, I had to give up.

Getting the ReCaptcha code

  1. Go to https://drivetest.ca/book-a-road-test/booking.html#/validate-driver-email
  2. When the page loads, open the Developer Tools in your browser and click on the Network tab.
  3. Click on the checkbox next to "I'm not a robot" and follow the verification steps until there's a green checkmark next to it.
  4. When you become verified, a URL in the Network tab of the Developer Tools will appear that will start with https://www.google.com/recaptcha/api2/userverify?k=... although browsers like Chrome will show it as userverify?k=...
  5. Click on this URL and inside Preview, look for a very long string. That long string is your ReCaptcha code, enter that into the script.