Develop PS5 Availability Tracker Using Python

PS5 is a hot commodity these days. Every gamer in the world is trying to get a hand on it. Since its launch its availability in stores has been very low. Some people have been running trackers to inform others about availability of PS5. In this post, I am sharing the code that can help you write your PS5 tracker using your Python skills.

I am using BestBuy's API to get information about PS5 availability. For this API to work, you will need to register with BestBuy API program. If you are not able to sign up for their API key, you can use HTML parser to download content of page from BestBuy page and then look for anchor text inside certain HTML elements.

-- ps5_tracker.py --

import requests
import json
from email_sender import EmailSender
from sms_sender import SmsSender
from types import SimpleNamespace
from config import Config

class Product:
    def __init__(self, dict):
        self.name = dict["name"]
        self.sku = dict["sku"]
        self.orderable = dict["orderable"]
        self.inStoreAvailability = dict["inStoreAvailability"]
        self.onlineAvailability = dict["onlineAvailability"]
        self.salePrice = dict["salePrice"]
        self.onlineAvailabilityUpdateDate = dict["onlineAvailabilityUpdateDate"]
        self.inStoreAvailabilityUpdateDate = dict["inStoreAvailabilityUpdateDate"]

class BestbuyProductTracker:
    def __init__(self, apiKey):
        self.apiKey = apiKey

    def search_products_bysku(self, skus):
        product_list = []
        skuParams = ""
        for sku in skus.split(","):
            skuParams += f"sku={sku}|"
        #remove last pipe
        if len(skuParams) != 0:
            skuParams = skuParams[:-1]
        #build rest api url
        request_url = f"https://api.bestbuy.com/v1/products"\
            f"({skuParams})?format=json"\
            "&show=sku,name,salePrice,onlineAvailability,orderable,"\
            "inStoreAvailability,onlineAvailabilityUpdateDate,inStoreAvailabilityUpdateDate"\
            f"&apiKey={self.apiKey}"

        try:
            response = requests.get(request_url)
            search_result = response.json()
        
            if "products" in search_result:
                products = search_result["products"]
                for product in products:
                    product_list.append(Product(product))
        finally:
            pass

        return product_list

tracker = BestbuyProductTracker("BESTBUY_API_KEY")
products = tracker.search_products_bysku("6426149,6430161")
if len(products) != 0:
    app_config = Config()
    app_config.load()
    email_sender = EmailSender(app_config.configuration.emailAccount)
    sms_sender = SmsSender(app_config.configuration.smsSettings.key, 
                           app_config.configuration.smsSettings.secret)
    for product in products:
        if (product.orderable.lower() != "soldout"):
            try:
                email_sender.sendEmail(subject=f"{product.name} is available",
                                   message=f"{product.name} is available. Go get it!\n\nThanks", 
                                   fromEmail="myadmin@example.com", 
                                   to="foobar@gmail.com",
                                   fromName="World of Hobbycraft")
            finally:
                pass
            # Send SMS message
            try:
                sms_sender.send_message(app_config.configuration.smsSettings.fromNumber, 
                            "toPhoneNumberHere", 
                            f"{product.name} is available")
            finally:
                pass

I have set up a scheduled task on my Windows machine. This task executes my ps5_tracker.py file every 10 minutes. As soon as orderable property of product will change to a value other than soldout, it will send email message and SMS message to recipients signed up for my service. If you need a full working package for this tracker, feel free to send me a message.

Search

Social

Weather

20.0 °C / 68.1 °F

weather conditions Clouds

Monthly Posts

Blog Tags