How this python script help me buy an iPad? Python Automated Emails.

N Nithin Srivatsav
2 min readJan 28, 2021

I was really enthusiastic on buying an Ipad ( For productivity purposes )

And was also very keen on buying it on flipkart. ( Why? Don’t ask. Don’t tell. )

However, the issue was, the model I wanted to buy was on high demand, so I never got an opportunity to book one, it went out of stock before I made it to the payment gateway.

Since it is all FCFS, I decided to be the first to be notified of when it is back on stock.

Nerd-ness kicking in!

Python Script to check if it is available. If yes, send me a mail.

Step 1:
All I wanted to understand was to understand the difference between the pages when a product is ‘available’ vs ‘not available’.

So opened two products, one in stock and the other out of.

In Stock
Out of Stock

So after viewing the pages thoroughly, the main difference was the ‘BUY NOW’ button.

Eureka!!

Step 2:

Algorithm:

  • Import libraries
  • Request the website
  • Check for BUY NOW button
  • If exists, Send email

Okay so the script is ready,
All we have to do now is write a cron job that runs this script every 1 minute.

  • Fire up the terminal
  • Type in “crontab -e”
  • Add the following line to the file
    * * * * * path-to-python path-to-alerts.py
  • Save and Exit.

That’s it. We now have a script that sends us an email as soon as the Ipad is available.

Note: One needs to do some security changes in the google account in order to send mail via 3rd party apps. Follow the instructions that pop up to get it sorted.

Until next time!!

--

--