Chanky
3 min readMay 14, 2022

--

Best Buy GPU Stock Bot with Requests and Discord API — A Web Scraping Project

The stock of GPU’s have gone down ever since the trend of bitcoin mining has popped up. Nvidia’s 30 series graphics cards come scarce and require some strategy to get a hold of in modern times. These strategies consist of going to a Micro Center and waiting in line as soon as they open in hopes of getting your hands on one of these monsters for stock price, or buying at market price and sacrificing an unreasonable amount from your wallet due to inflation.

To combat this problem, I took a look into many different sites and what they had to offer. The conclusion is as follows; While the 30 series GPU market is inflated for after market cards, the founders edition card prices remained at stock price. One website that offered these cards was Best Buy, however, due to high demand these cards are constantly out of stock.

To solve the problem, I developed a script that used some simple requests to check the state of the add to cart button on specified links.

Specifying which Best Buy links we want our Bot to check

I chose links to products that remained at stock price as choosing products with inflated prices would defeat the purpose of solving this problem. We store this in a list that we will later iterate through.

We then want to find out what the state of the button is. We can do that with these lines of code using the requests to get the html state of the site at the time of the request and Beautiful Soup to find the exact element we are looking for, which in this case is a button element with the class:

{“data-button-state” : ‘ADD_TO_CART’}

This function will append elements to our previously defined empty list based on the state of the button. Now that we have all this information to check stocks and price, I needed a way to notify myself that the item was in stock. The most familiar API to me was Discord’s messaging system. This wasn’t difficult to implement with requests. The sendDisc() function is defined as follows.

This is sent every time the script starts up in order to confirm the script was working

We pass the message with information of the card’s availability and the price that we scraped with Beautiful Soup to discord along with the channel ID which I specified to be the ID of a channel in my personal discord server. Then we add a little systemd symlink to start the script every time the computer boots up, use pickle to store the list so we don’t get spammed, and wallah!

We have fully automated the checking process! (Don’t mind the date as there weren’t any GPU’s in stock recently)

--

--