How I created an app with Heroku and Twilio to check a website every minute and call me if the site changed, notifying me of available Banksy artwork.
I was vacationing in Florence when I first noticed Gross Domestic Product™, a storefront from the artist Banksy.
Banksy was about to release new artwork due to a copyright dispute, and he hadn’t released new artwork to the public for over a decade. This was potentially a historic opportunity.
The website read “Coming soon” so I assumed it would open suddenly with everything for sale — what’s known as a “drop”.
As a Banksy fan, I began compulsively refreshing the website. Then I started thinking it was unnecessary to spoil a nice vacation when I could have a machine do the work for me.
I did a quick search on the web (and the App Store) to see if I could find something that would periodically check the website and send me a message if it changed. I was disappointed to find that most apps would only check every hour. Definitely not fast enough!
Luckily I know some Python, how to set up a quick app on Heroku, and how to use Twilio to send text messages.
Making the app
Thanks to jet lag, I woke up at 3 am. When better to start hacking?
I set up a phone number on Twilio that could programmatically text me. Then I downloaded the how-to Django app from Heroku and began customizing it.
I wanted the app to download a copy of the HTML source code from the website and compare it to a previously downloaded version. I used the Python Requests library to fetch the contents of the site and save it to a file called grossdomesticproduct.html. I then used that file to compare new requests.
I’d like to mention that the grossdomesticproduct.com source code was very tidy, so hats off to Banksy’s web developer! 🎩
Now that I had a way to compare the site, I needed it to send me a text message. Luckily, with Twilio’s Python SDK, that was super easy!
At this point I wanted to quickly test my code, so I set up a website — banksy-pickup.herokuapp.com — that would run my code when I visited.
It worked!
Press enter or click to view image in full size
Next I needed to get this bit of code checking the website every minute.
Heroku has an add-on called Heroku Scheduler that can be configured to run a script on a regular basis. Unfortunately the fastest it can run is once every 15 minutes. Bummer.
For speed, I needed to use a Python process called APScheduler. I updated the example clock.py script from the Heroku APScheduler documentation to fit my needs.
I started this process using heroku ps:scale clock=1 and now everything worked!
I configured the app to send me a text message every morning at 8 am, just to let me know it was still running.
I was quite pleased with my progress… but what about timezones? Banksy lives in the UK, so what if the site updated while I was asleep?!
To make sure I got notified in a timely manner, I decided to have the app call me. I put a “Banksy Alerts” phone number in our Favorites and then configured calls from Favorites to always come through, regardless of the hour.
Making a phone call with Twilio was just as easy as sending a text:
Note that when the app called us, it just played the default audio from Twilio, a rickroll. We didn’t actually need to have it say anything because we would know that when we got the call, we should just check the website.
The call
For about a week I patiently waited to be notified of any updates.
I was at the gym, in the middle of doing some crunches, when I got the call.
Eek! I quickly opened the website on my phone.
At this point I discovered that this was not, in fact, a drop.
Instead visitors could add an item from the shop to their cart with a short message and would be selected at random to make the purchase.
The result
First, I’m thrilled my little app worked!
And honestly I’m relieved this wasn’t a race to visit the website. Banksy seems too cool for that.
I also realized that I can forget how much fun it is to work on a new coding challenge. It’s creative and rewarding to quickly build an app from scratch to solve a problem.
Am I sad to not get a million dollar artwork? A little, but not too sad. The journey was the reward.
Press enter or click to view image in full size
W̶h̶y̶ does art matter?
I wrote an app to check grossdomesticproduct.com every minute and call me if it changed. It worked, but I didn’t get a painting. I’m not disappointed. It was fun just to make something.
Here’s the full source code.