I built a basic little site called What Was On TV Last Night?
The only purpose of this site is to grab and send last night’s TV episodes and email the list out to the subscribers. I built this for myself so I didn’t have to spend any time remembering when certain shows were on, when they come back to air after hiatus and thus never miss anything I like to watch.
For quite some time, I could not get this to work at all (since I’m a novice coder at best) but I persisted in an attempt to improve.
I had to hack MailChimp a bit, and struggle with ChatGPT (posts on these topics are in the works).
After the newsletter was finally working, I found a very useful API (TVMaze) which provides the art for each show. However, the API has a limitation that made this VERY slow. To load all the art for any day would take 3-5 minutes. This is in fact too slow to use in MailChimp at all. It would time out in the campaign creation process and not let me send any emails fueled with this content.
So, I built a simple little “cache” hack to get around this limitation.
At 4am, the newsletter content gets built by a cron job pinging a file and the content is dumped into a static HTML file created on the fly. The server only has to ping one time every day and update the static file.
From there, the site can show a sample and the newsletter can send since it now loads nearly instantly.
Sample code is below the post if you want to use any of it! It’s very useful if you have a reason to replicate the same content over and over but don’t want to ping the data sources every time. Fundamentally, it’s the same concept as why you would use a caching system.
My favorite part about programming is solving a problem – first, I wanted to make it easier to simply know what shows I was missing. Next, I needed to get an email to automatically send. Finally optimizing and making it faster led to this simple little hack to reduce the load time and minimize the server and API usage.
This is what makes coding fun.
Here’s the code you can use: