I woke up this morning later than I expected to, because my alarm didn’t go off. This wasn’t really a problem given it is a Sunday, but it was concerning as my computer does this task for me.
I’ve been refactoring my personal assistant program that, among many things, regulates my sleeping schedule and I thought perhaps I broke something (as I am wont to do… often). Though, upon inspection I came to find that it wasn’t my fault, but rather that my holiday function wasn’t working.
It’s not the most elegant code, but it returns today’s holiday as a string (if it is a holiday), or returns None
if today isn’t special. It does this by reaching out to Holiday API (a wonderful, simple, RESTful API with an exhaustive list of country holidays worldwide) to ask, “is today a holiday?” Normally, I get a json object back which I can treat like a dictionary:
Which tells me, “No. Today isn’t special.” Or:
Which tells me all sorts of things are going on.
Unfortunately for me, today I got a response I was not expecting:
Which tells me if I want to know if today is a holiday, I have to pay $9/mo. Disappointing. Of course, I get it – this service has been free for quite some time, and I’ve been benefiting off the hard work of the likes of Josh Sherman for a fortnight. Given how lovely the Holiday API service is, it’s not an outrageous assumption to say how popular it probably is, and bandwidth isn’t free; neither is hosting, or domain registration, etc. – so I wish them all the best in their future.
However, my use case is an alarm clock for which I’m not about to spend a monthly subscription to run on my own computer. Thankfully, someone has already made a python library which handles holidays with the bonus of supporting custom holidays as well! So now that I’ve found my henceforth solution, I’ve updated my holidayDict function:
Much better, methinks.