Recent changes Random page
GAMING
Lifestyle
 
Biomed Tech
Diabetes Wiki
Sleep Apnea
Autism Wiki
Quit Smoking
Depression Wiki
See more...

Forum:Using woots xml page

From Woot Wiki

Jump to: navigation, search
Forums: Index > Watercooler > Using woots xml page


[edit] Introduction

THIS IS A PROOF OF CONCEPT ONLY IF YOU USE THIS SCRIPT FOR A LIVE CHECKER YOU WILL UNDOUBTEDLY GET BANNED BECAUSE THERE IS NO CACHING INVOLVED WITH THIS

Please see Forum:Woot_dev_offers_some_guidance for information.

I quickly made a script that shows how to access the data in that page. You can use this as a base to plug into your particular implementation of the cache.

Awesome. Wouldnt just copying the file lcoally, then having JS read it for AJAX save the server some load :) letting the end user browser do the parsing, opposed to the server do it saves the webhost. Check out the google code forums, we've been discussing that for awhile--ikishk 19:58, 1 February 2007 (UTC)

[edit] The Code

<?php
/**
 * wootxml.php
 * 
 * DO NOT CALL THIS FILE DIRECTLY WITH EACH REQUEST, IT WILL ALWAYS HIT WOOT'S SERVERS
 * REMOVING THE PURPOSE OF A CACHE TO BEGIN WITH.  THIS IS PROOF OF CONCEPT CODE ONLY.
 * 
 * It could also be used instead of the code to query woot.com AFTER you have ensured 
 * the cache has expired
 *
 * I didn't parse the individual products section.  Only advantage to that would be the
 * product description being a little more detailed and could be plugged into a search
 * form.
 *
 * I also could not figure out how to detect the bouncing "almost gone" link.  It seemed
 * to kick in once the sold value went about .90, not sure if that's what determines it
 * (this has been confirmed as how the "almost gone" link works, by 90% sold)
 *
 * THIS IS RELEASED INTO THE PUBLIC DOMAIN.  YOU MAY USE THIS SCRIPT FOR ANY PURPOSE
 * WITH OR WITHOUT GIVING CREDIT
 * 
 * *updated to work with new xml format woot is using.  Basically woot's special values
 * have "woot:" prefixed.  If it ever changes, looking at the $wootdata array will show
 * the new values
 * 
 * @author Todd (vrillusions)
 * @date 2007-02-01
 */


//Define Settings
$source="http://www.woot.com/salerss.aspx";
$timeout = 3; // set to zero for no timeout


//retrieve file
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $source); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
$file = curl_exec($ch);
curl_close($ch);


// parse the xml file
$p = xml_parser_create();
xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($p, $file, $values);
xml_parser_free($p);


//process the array so we can refrence them
$wootdata = array();
foreach ($values as $value) {
	//level of 4 is the details for the item (and all tags should be unique)
	if ($value['level'] == 4) {
		$wootdata[$value['tag']] = $value['value'];
		
		if ($value['tag'] == 'wootoff') {
			//wootoff has a 'sold' attribute of the percentage SOLD
			// so a value of .75 means there is 25% availiable
			$wootdata['sold'] = $value['attributes']['sold'];
		}
	}
}


echo '<pre>';
//print_r($values);
//print_r($wootdata);

echo 'The title is:        '.$wootdata['title']."\n";
//hiding since it's really long and hard to see rest
//echo 'The description is: '.$wootdata['description']."\n";
echo 'The price is:        '.$wootdata['woot:price']."\n";
echo 'The condition is:    '.$wootdata['woot:condition']."\n";
echo 'The is it soldout (true = yes, false = no)?:    '.$wootdata['woot:soldout']."\n";
echo 'Are we in a wootoff (true = yes, false = no)?:  '.$wootdata['woot:wootoff']."\n";
echo 'percentage sold:     '.$wootdata['sold']."\n";
echo 'The purchase url:    '.$wootdata['woot:purchaseurl']."\n";
echo 'The discussion page: '.$wootdata['woot:discussionurl']."\n";
echo 'Thumbnail image:     '.$wootdata['woot:thumbnailimage']."\n";
echo 'Standard image:      '.$wootdata['woot:standardimage']."\n";
echo 'Detail image:        '.$wootdata['woot:detailimage']."\n";

die();

?>