Welcome back to ": Code Against the Clock :!" – the blog series where I transform mundane tasks into streamlined, time-saving marvels. Today, I'm thrilled to share a project where I turned a repetitive, manual chore into an automated powerhouse. Ready to see how you can save time and add a touch of excitement to your workflow? Let’s dive in!
As many of you know, I work as a full-stack developer at a startup. We use Keka for managing employee attendance, which requires manually clocking in and out each day when entering and leaving the office. The issue? Sometimes, I forget to clock in or out, which results in my attendance being marked as not present. This means I have to raise a ticket in Keka to correct it – a tedious task that I wanted to automate.
Initially, I looked for an API provided by Keka for this purpose, but unfortunately, they don't offer one. No problem! As a developer, I took on the challenge of solving this myself. I started by analyzing Keka’s website to understand how it works. Using the network tab in my browser’s developer tools, I identified the endpoint triggered when clocking in and out.
I wrote a simple Node.js script using fetch to make requests with a Bearer token in the header, and it worked. However, there was a catch: the Bearer token expired daily. I discovered that the website retained the refresh token in local storage, which was used to obtain a new Bearer token when the old one expired.
After adapting my script to handle this, I faced a few more challenges:
To tackle these issues, I devised the following solutions:
[CRON Job (Every 15 minutes)] ---> [Node.js Script] \-------> [Check Time] ---> [Clock In/Out] \-------> [Notify (Slack)]
Once everything was in place, I scheduled a cron job to run my script every 15 minutes. This setup worked flawlessly for a year, automating my attendance management efficiently.
After a year, I decided to enhance the solution by converting the script into a Chrome extension. This made it easier to share with colleagues. Here’s how the extension works:
[CRON Job (Every 15 minutes)] ---> [Node.js Script] \-------> [Check Time] ---> [Clock In/Out] \-------> [Notify (Slack)]
This streamlined approach made managing my attendance even easier!
Note: If you’re interested in the source code, feel free to reach out to me!
Have you ever automated a task using code? Share your experiences and tips in the comments below! What tasks do you wish you could automate? Let's discuss!
Thanks for joining me on this automation journey. Don’t forget to subscribe to my blog for more tips and updates. Happy coding!
The above is the detailed content of Code Against the Clock : Automating Attendance Management. For more information, please follow other related articles on the PHP Chinese website!