Shop like a nerd
--
Or at least think about yourself that way…
Have you ever desired something you couldn’t get? Or wanted to gift somebody with something which was unavailable? These are serious philosophical questions. Today we will focus on a minor thing though, a roll neck jumper for my wife.
The object of lust
The roll neck jumper comes from MLE Collection, a fashion brand by Polish blogger Kasia Tusk. The products are quite expensive (at least for Polish standards), but they are sold out within 15–20 minutes after their status is set to “available.” It makes a statement. Of course, you can subscribe to an e-mail alert, but as you can imagine it may not be enough. What could possibly a nerd do to gain an advantage?
The peeker
It would be great to have somebody peek every minute to check if the product has become available. We do not want to do it ourselves, because it’s boring. Bots don’t get bored. Here’s how one of them could look like implemented in Python:
Since we’re not sure how does the HTML look like when the product is available, the code checks whether the product is unavailable. The script will run until the site’s code changes. Now we need a mechanism to let us know about the change.
Setting-up the app
I’ve chosen a Flask app since initially I wanted to deploy it on some cloud instance (finally I didn’t). A Flask-Mail package allows us to send emails from a running script. The setup is quite straightforward:
Note that in order to connect from a Flask app to your email account you have to be logged on your browser. In the case of Gmail, you have to generate an additional password in App passwords section of your Google account’s settings. Before you do it, please read the security information!
Putting it all together
We have the availability checking mechanism and email sending mechanism. It’s time to put it all together!
The app can be run by ‘python app.py’ command (in Unix environments). The app can be activated by visiting ‘http://127.0.0.1:5000/’ in your browser. Now you have to wait for the e-mail to come. Please keep in mind that the app has to work in the background on your machine.
Is it pretty? No. Is it rocket science? Nope. But it does its job! I’ve received an e-mail from my app 3 minutes before the official availability subscription message. I made the purchase and here it is!
Fun fact: the product got available as I was debugging the code, so I had two reasons to be happy: my app was correct, and I could purchase the jumper!
Summary
The mini-project took me one evening. In addition to obtaining the jumper and learning a lot, I had fun and satisfaction. Solving even the smallest real-life problem like that made me feel like a nerd.
Gargoyles
You may wonder why the GitHub Gists are called gargoyles? I love Terry Pratchett’s books where the name’s inspiration comes from. The creatures are alive there and according to the Discworld & Terry Pratchett Wiki, “Gargoyles are extremely good at sitting still for a long time and watching the goings-on, therefore excellent job candidates for stakeout Watchman.” This was what we needed!