How I Created a Python Script to Buy the Intel Core i9 10900k

Nawar Aswad
Python in Plain English
4 min readJul 1, 2020

Since Intel announced the new 10th generation Core desktop processors back in April, I couldn’t wait to upgrade my now 3-year-old PC.

The new Core i9 10900k features ten cores, 20 threads and a massive 125-watt TDP. Out of the box, the 10900k can run on all cores up to 4.9 GHz and can reach single-core turbo speeds of up to 5.3 GHz.

As a software developer and PC enthusiast, I knew I wanted to get the best of the best; however, I didn’t think it would be such a roller coaster to find one.

The 10th generation series processors launched late May, however, up to publishing this article, many variants, including the 10900k, are challenging to find. Even if they manage to go in stock, they disappear within minutes with such high demand.

As excited as I was to get the processor, I wasn’t about to sit there and refresh web pages all day in hopes of finding one. Then it came to me: let my computer do it for me. Here is how I made the Python script that got me my shiny new processor earlier than most.

Python has fantastic libraries for this task, such as bs4 and stmplib.

import bs4, requests, smtplib, time

The script consists of two functions, getStatus and sendEmail.

The getStatus function will search for the stock at a particular retailer, and the sendEmail function will notify me if the retailer has it in stock.

Let us start with getStatus:

getPage = requests.get(‘ProductPageGoesHere’)

First, we let Python open the web page of our product. We can replace ‘ProductPageGoesHere’ with the link to the product at our desired retailer.

Next, we initialize the HTML parser that will parse through the HTML content of the web page.

Now comes the tricky part: knowing what to look for. We must first find the class of the HTML content in which the current stock is under. The class name is really dependent on how the retailer designed their product web page.

As a hint, you can try inspecting the element of the stock number on the webpage and it will show its location in the HTML script.

For one of the online sellers I was tracking, the class name was dependent on whether or not the product was in stock. If it was not in stock, the class name would be “InventoryState_BackOrder”, and if it was in stock the class name would be “InventoryState_InStock”.

To check if it was in stock, I checked to see if the class name was “InventoryState_InStock”.

If this is the case, the returned length would be greater than 0 which will trigger the sendEmail function to notify me. The purpose of the sleep function is to make the program check every 10 seconds without hogging computer resources.

Now comes the sendEmail function:

There isn’t really much logic here, other than creating a connection with Gmail, logging in and sending the message; it’s pretty straight forward.

Here is the code all together:

Feel free to also check it out on Github.

After running this script for four different retailers, three days continuously, I was finally able to purchase the Core i9 10900K processor.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Written by Nawar Aswad

Software Developer, PC Enthusiast, and Part-time Author

No responses yet

What are your thoughts?