Signed copies of the masterpiece Folklore by Taylor Swift were briefly available to buy online at 2am AEST, 17/10/2020. Although copies were still available for those in the USA, the international copies were long gone by the time I noticed. I wasn’t keen on setting a 2am alarm to check each night, and I decided against freight-forwarding as that was looking expensive for a CD. After refreshing the page a few times without any luck, I thought there must be an easier way - and there was.

Folklore signed by Taylor Swift

It’s Python Time

I wrote a Python script that scrapes the product page for the international signed CD and checks for product availability. I do this by getting the text of the button on the page - “Add to cart” suggests availability where “Not Available” does not. Here is how to do that with BeautifulSoup.

import time
from pushbullet import Pushbullet
import requests
from bs4 import BeautifulSoup

def get_button_text( url ):
    "Get Button Text for Product Availability"
    page = requests.get(url)

    # Assume product is removed and stop if we receive status 404
    if page.status_code == 404:
        return

    soup = BeautifulSoup(page.text, "html.parser")

    # Find the add to cart button
    cart = soup.find('button', class_='ProductForm__AddToCart')
    if not soup:
        return

    # Return the buttons text
    return cart.text.strip()

The script loops every minute until the product goes from unavailable to available (it just checks the button says “Add to cart” instead of “Not Available”). When the product becomes available, the script sends a Pushbullet notification to my phone.

url = "https://store.taylorswift.com/products/the-limited-edition-signed-in-the-trees-edition-deluxe-cd-international-customers-only"
# Pushbullet API Key
pbKey = 'welovetaylorswift'
# Time between checking the page
waitTime = 60
# Keep trying while product is not available
while (get_button_text(url) == "Not Available"):
    print("Not available")
    time.sleep(waitTime)

Now we’re looping until the product is no longer available, or if the page gets taken down or something. When we break out of the loop, let’s check if we can actually “Add to cart” with the button, then send a notification through the Pushbullet API.

if(get_button_text(url) == "Add to cart"):
    print("~~~ PRODUCT AVAILABLE - SENDING NOTIFICATION! ~~~")
    # Pushbullet notification to BUY!
    pb = Pushbullet(pbKey)
    pb.push_note("TAYTAY", url)
else:
    print("Page not found! Please check the url parameter.")

Easy!

I set my phones Pushbullet notification tone to an obnoxious sound sure to wake me from the deepest of sleeps, and made sure it would not take notice of the phones “Do Not Disturb” mode.

It’s Taylor Time

At 3:28am AEST, 20/10/2020, I was awoken by the obnoxious sound I spoke of earlier. It took me a moment to realize what was going on - my script had worked its magic!

Pushbullet Notification

Within 3 minutes I had very sleepily purchased my very own signed copy of Folklore.

Juzz and a copy of Folklore signed

I think the script has used all the magic it once held. I wouldn’t trust it moving forward without further testing, but it can be found here regardless.