All pastes #2079044 Raw Edit

Unnamed

public text v1 · immutable
#2079044 ·published 2011-08-30 01:07 UTC
rendered paste body
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="10" > 
<title>Argos Stock Checking Engine</title>
</head>

<body>

<?php
function get_url_contents($url){
        $crl = curl_init();
        $timeout = 5;
        curl_setopt ($crl, CURLOPT_URL,$url);
        curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
        $ret = curl_exec($crl);
        curl_close($crl);
        return $ret;
}
function readLine($file, $line_num, $delimiter="\n")
{
    /*** set the counter to one ***/
    $i = 1;

    /*** open the file for reading ***/
    $fp = fopen( $file, 'r' );

    /*** loop over the file pointer ***/
    while ( !feof ( $fp) )
    {
        /*** read the line into a buffer ***/
        $buffer = stream_get_line( $fp, 1024, $delimiter );
        /*** if we are at the right line number ***/
        if( $i == $line_num )
        {
            /*** return the line that is currently in the buffer ***/
            return $buffer;
        }
        /*** increment the line counter ***/
        $i++;
        /*** clear the buffer ***/
        $buffer = '';
    }
    return false;
}

// curline is the current line in the postcode file (updated after each cycle)
$curline = 1; // default

// get next postcode (current is kept track of in argos_cur.txt)
$curfilename = "argos_cur.txt";
$cf = fopen($curfilename, 'r');
if($cf != false)
{
	$curline = fread($cf,10);
	echo "READING curline $curline";
}
//echo $theData;
fclose($cf);


$resultfilename = "argos_results.html";
//$item = "5190197"; // ipod
$item = "5086043"; // hp touchpad 16gb
//$item = "5086050"; // hp touchpad 32gb

$postcode = "hg11dl";

while(true)
{
	
$item = "5086043"; // hp touchpad 16gb
$postcode = readLine("postcodes_uk.txt",$curline);
$postcode = str_replace(" ","",$postcode);

// get the stock checker page
echo "<a href=$resultfilename target=_blank>results</a>";
echo "<br>checking item $item";
echo "<br>checking postcode $postcode";
$data = get_url_contents("http://www.argos.co.uk/webapp/wcs/stores/servlet/ISALTMStockAvailability?langId=-1&storeId=10001&checkStock=true&partNumber_1=$item&qasSearchTerm=$postcode");

//echo $data;

$timestamp = date("m/d/Y h:i:s a",time());

// parse for and append result to file
$rf = fopen($resultfilename, 'a') or die("can't open file");
$pos = strpos($data,"inStock");
if($pos == false) {
	echo "<font color='#FF0000'>OUT</font>";
	fwrite($rf, "<br>$timestamp - $postcode - $item - <font color='#FF0000'>OUT</font>");
} else {
	echo "<font color='#00DD00'>IN</font>";
	fwrite($rf, "<br>$timestamp - $postcode - $item - <font color='#00DD00'>IN</font>");
}
fclose($rf);


// DO IT AGAIN FOR THE 32GB ILM LAZY LOLOLOL
$item = "5086050"; // hp touchpad 32gb

// get the stock checker page
echo "<a href=$resultfilename target=_blank>results</a>";
echo "<br>checking item $item";
echo "<br>checking postcode $postcode";
$data = get_url_contents("http://www.argos.co.uk/webapp/wcs/stores/servlet/ISALTMStockAvailability?langId=-1&storeId=10001&checkStock=true&partNumber_1=$item&qasSearchTerm=$postcode");

//echo $data;

$timestamp = date("m/d/Y h:i:s a",time());

// parse for and append result to file
$rf = fopen($resultfilename, 'a') or die("can't open file");
$pos = strpos($data,"inStock");
if($pos == false) {
	echo "<font color='#FF0000'>OUT</font>";
	fwrite($rf, "<br>$timestamp - $postcode - $item - <font color='#FF0000'>OUT</font>");
} else {
	echo "<font color='#00DD00'>IN</font>";
	fwrite($rf, "<br>$timestamp - $postcode - $item - <font color='#00DD00'>IN</font>");
}
fclose($rf);


// move curline to next
echo "curline $curline";
//$curline++;
$curline = $curline + 100;
echo "curline $curline";
$cf = fopen($curfilename, 'w');
fwrite($cf, $curline);
fclose($cf);

}

?>


</body>
</html>