My middle son is currently eligible to take the road test[^1] for his driver's license!
The problem is that we're in the middle of a global pandemic so Goverment services are spotty at-best. First the DMV was closed for months, now there's a huge backlog of people trying to get road tests.
The timeline of our attempts went roughly like this:
- Jul 2020 - Check the scheduling website and see they're booked through the end of Aug 2020
- Aug 2020 - Find out that Sep 2020 tests become available on Aug 14
- Aug 13, midnight - Go to scheduling website to find it's crashed.
- Aug 14 - 16 - Periodically check scheduling website to find it's either down or still only showing Aug
- Aug 17 - Site is up and showing schedule for Sep 1 - 18 and they're all booked 😡
At this point, I do what any self-respecting programmer would do. I write a script to automate this whole process.
The idea is something like this:
- Grab the contents of the scheduling webpage
- Check to see if there are any open days
- If 2, send me a text message
- Repeat every few minutes
There are obviously a million ways to go about this so I decided to go with my old standby, PHP[^2].
Here are 3 libraries that made this little script a breeze:
- Symfony DomCrawler for parsing HTML
- Symfony CssSelector for doing media queries on our parsed HTML
- Twilio for sending text messages
And here's the code which took less than 20m to cobble together.
The fun part is, I never even had to run it as a cronjob.
On the third manual test, I got a hit for availability on Sep 15, 2020!
[^1]: A little background for anyone outside of the US (or Kentucky).
Here in Jefferson County Kentucky, you take a written test to get your driver's permit at age 16. With the permit, you can drive as long as there's a licensed adult over 21 in the car with you. After 6 months of driving with your permit and logging 60h of driving time, you're eligible to take the road test where you have to drive a car with a DMV (Department of Motor Vehicles) employee with you and complete certain tasks (parallel parking, etc). Once you've passed the road test, you get your provisional driver's license which lets you drive without an adult (with some restrictions)
[^2]: Yeah, I know PHP isn't cool. Most of the stuff you hate about it hasn't been an issue since PHP 5 and PHP 7.4 (especially using something like Laravel) is downright tasty. Whatever. You do you.