PHP Woot Checker – Tech, Wine, and Shirt Woot
If you haven't heard of Woot.com, you've been living under a rock. For those who have been under the proverbial rock, here's the plot:
- Every day, Woot sells one product.
- Once the item is sold out, no more items are available for purchase.
- You don't know how many of the item is available and you may only buy three at a time.
- The shipping, regardless of product price and quantity, is $5.00.
- Every once in a while (usually once a month), Woot has a "Woot-off", where they sell item after item until everything is sold out.
- Even more rare is the "Bag o' Crap." What are you buying? A bag of crap, but that "BOC" could be a laptop bag strap or a big screen TV. Good luck getting through the checkout process though -- BOC's usually take down the server.
- Woot branched out from simply tech products (woot.com) to wine and t-shirts.
Needless to say, Woot is an interesting website. I've created a PHP script that returns the product's name, price, and image.
//get the page content
$woot_content = file_get_contents('http://shirt.woot.com');
//parse for product name
$name = get_match('/<h3[^>]*>(.*)</h3>/is',$woot_content);
//parse for product price
$price = get_match('/<div class="price"><span id="PriceSpan">(.*)<dl class="saleSpecs">/is',$woot_content);
//parse for product image
$image = get_match('/<div class="saleContainer">(.*?)/>/is',$woot_content).' />';
//parse for product sold out?
$sold_out = substr_count(strtolower($woot_content),'sold out!') ? 'Sold Out!' : 'Product Left!';
$content.= '<h1>Product Name</h1>'.$name.'<br /><br />';
$content.= '<h1>Product Price</h1>'.$price.'<br /><br />';
$content.= '<h1>Product Image</h1>'.$image.'<br /><br />';
$content.= '<h1>Product Sold Out?</h1>'.$sold_out.'<br /><br />';
//gets the match content
A few notes about the code:
- You can get the content using the file_get_contents() function or my URL Download Content function. Your preference will depend on your server's security settings.
- You may use the following URL's, depending on the content/product you want:
Save 20% with discount code
Standard jQuery Element Creation
Looks exactly like writing out...
Whenever you have a long page worth of content, you generally want to add a "top" anchor link at the bottom of the page so that your user doesn't have to scroll forever to get to the top. The only problem with this method is...
With all of my recent command line tutorials, I've really gotten excited about the shell's simplicity and realized the true power of using the underlying technology of pretty UIs. Since I work from home, I spend a lot of time on video calls, so when...
I'm as much of a fan of application UIs as anyone else but I'm finding myself working more and more from the command line lately. Much of that is becoming obsessed with media manipulation but I'm forcing myself to use less UIs so that I...
When I conned my way into my first professional programming gig, I didn't really think much about money -- just that I was getting my foot in the door. But as my career has gone on, I've been more aware of money, investing, and retirement. I've recently...
One interesting aspect of web development is geolocation; where is your user viewing your website from? You can base your language locale on that data or show certain products in your store based on the user's location. Let's examine how you can...
Visuals are everything when it comes to media. When I'm trying to decide whether to watch a video on Netflix, it would be awesome to see a trailer of some kind, but alas that isn't available. When I'm looking to download a video on my computer,...