DEV Community

Cover image for Node.js + Cron === πŸ’ͺ🏼πŸ’ͺ🏼πŸ’ͺ🏼
jbroomer
jbroomer

Posted on

Node.js + Cron === πŸ’ͺ🏼πŸ’ͺ🏼πŸ’ͺ🏼

TLDR; wrote script to automate new gym registrations everyday. Tell me in the comments below what you have done to solve your COVID quarantine problems.

CODING FOR COVID Everyone has been affected by COVID-19 in some way. Many states were shutdown for an extended period of time, something that I don't think most people have come close to experiencing. But that doesn't mean life can't go on! As programmers we are to be critical thinkers, looking to solve our problems and hinderances. I want to talk about one that I solved and hear about your own! I call it: Coding for Covid.

Businesses in my area have begun their reopening. I guess I should really write, reopening*****, since there are numerous strict health and safety guidelines. One such business reopening I have been anticipating the most is the gym, which naturally have some of the strictest requirements. For example, almost 2/3 of the gym equipment is closed off, the usual 24/7 gym hours have been cut back to 7:00am-6:30pm (with an hour in-between that they close for cleaning), and to top it all off, you have to register two days in advance for one of the allotted time slots that has a maximum capacity of 25 people. This is a large facility. I'm sure you can imagine how quickly the most popular time slots fill up.

First, let me be clear, I am completely on board with the guidelines and keeping everyone safe.

As dedicated to my workout regimen as I am, time slots only open two days in advance and I simply cannot be online at the exact time each day to secure a slot. So, this got me thinking.

I took one look at the network requests on the registration website and knew I could start cooking something up. I decided to use Node.js to write the script and axios to make the network request with the proper authentication. A couple hours later I successfully signed up to a class through my terminal.

Now, I needed this to run at the same time every day so obviously my head immediately went to Cron Jobs. However, I don't have a machine that will, reliably, be on all the time.

Cue in: Google Compute Engine

I configured a super low-end linux machine: lowest amount of RAM, standard 10GB storage, etc. I pulled down my script file from git and 20 minutes later I was ready to go.

Of course I took proper precaution to not sign up for any at risk time slots as, thankfully, I am not at risk. My next plan is to configure some quick commands to cancel my registrations to free up time for everyone else in the event that I cannot make it on a given day.

What have you done to Code for Covid?

Top comments (0)