Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div align="center" id="timer" style='color:black;font-size:24px;' ></div>
- <?php
- $time_start = microtime(true);
- set_time_limit(0);
- ignore_user_abort(1);
- function getContents($str, $startDelimiter, $endDelimiter) {
- $contents = array();
- $startDelimiterLength = strlen($startDelimiter);
- $endDelimiterLength = strlen($endDelimiter);
- $startFrom = $contentStart = $contentEnd = 0;
- while (false !== ($contentStart = strpos($str, $startDelimiter, $startFrom))) {
- $contentStart += $startDelimiterLength;
- $contentEnd = strpos($str, $endDelimiter, $contentStart);
- if (false === $contentEnd) {
- break;
- }
- $contents[] = substr($str, $contentStart, $contentEnd - $contentStart);
- $startFrom = $contentEnd + $endDelimiterLength;
- }
- return $contents;
- }
- $host = "localhost";
- $user = "buysexto_user";
- $pass = "123123123";
- $database = "buysexto_pdb";
- $con = mysqli_connect($host,$user,$pass,$database);
- $result = mysqli_query($con,"SELECT * FROM product");
- $sql = "ALTER TABLE `product` ADD `qty` int NOT NULL DEFAULT 0;";
- mysqli_query($con, $sql);
- $sql = "ALTER TABLE `product` ADD `fulldescription` LONGTEXT;";
- mysqli_query($con, $sql);
- $sql = "ALTER TABLE `product` ADD `specifications` LONGTEXT;";
- mysqli_query($con, $sql);
- $sql = "ALTER TABLE `product` ADD `sizing` LONGTEXT;";
- mysqli_query($con, $sql);
- $sql = "ALTER TABLE `product` ADD `productid` LONGTEXT;";
- mysqli_query($con, $sql);
- $counter = 0;
- while($row = mysqli_fetch_array($result))
- {
- $qty = (isset($row['qty']) ? $row['qty'] : null);
- if ($qty >= 0) {
- $counter++;
- $context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n')));
- $homepage = @file_get_contents("https://www.sextoydropshipping.ca/catalogsearch/result/?dir=desc&q=".$row['upc'],false,$context);
- $desc = "";
- if (strpos($homepage, '<h2>Product Description</h2>') !== false) {
- $desc = getContents($homepage, '<h2>Product Description</h2>', '</div>');
- $desc = end($desc);
- $desc = preg_replace('/(\s\s+|\t|\n)/', ' ', $desc);
- $desc = strip_tags($desc);
- $desc = ltrim($desc);
- $desc = rtrim($desc);
- $desc = mysqli_real_escape_string($con, $desc);
- $sql = "UPDATE `product` SET `fulldescription` = '$desc' WHERE `upc` = ".$row['upc'];
- mysqli_query($con, $sql);
- };
- $spec = "";
- if (strpos($homepage, '<strong>Specifications</strong>') !== false) {
- $spec = getContents($homepage, '<strong>Specifications</strong>', '</div>');
- $spec = end($spec);
- $spec = preg_replace('/(\s\s+|\t|\n)/', ' ', $spec);
- $spec = str_replace("<br>", "", $spec);
- $spec = str_replace("<ul>", "", $spec);
- $spec = str_replace("</ul>", "", $spec);
- $spec = ltrim($spec);
- $spec = rtrim($spec);
- $spec = mysqli_real_escape_string($con, $spec);
- $sql = "UPDATE `product` SET `specifications` = '$spec' WHERE `upc` = ".$row['upc'];
- mysqli_query($con, $sql);
- };
- $size = "";
- if (strpos($homepage, '<h3>Sizing Chart</h3>') !== false) {
- $size = getContents($homepage, '<h3>Sizing Chart</h3>', '</div>');
- $size = end($size);
- $size = preg_replace('/(\s\s+|\t|\n)/', ' ', $size);
- $size = str_replace("<br>", "", $size);
- $size = str_replace("<ul>", "", $size);
- $size = str_replace("</ul>", "", $size);
- $size = ltrim($size);
- $size = rtrim($size);
- $size = mysqli_real_escape_string($con, $size);
- $sql = "UPDATE `product` SET `sizing` = '$size' WHERE `upc` = ".$row['upc'];
- mysqli_query($con, $sql);
- };
- $productid = "";
- if (strpos($homepage, 'product" value="') !== false) {
- $productid = getContents($homepage, 'product" value="', '"');
- $productid = end($productid);
- $productid = preg_replace('/(\s\s+|\t|\n)/', ' ', $productid);
- $productid = str_replace("<br>", "", $productid);
- $productid = str_replace("<ul>", "", $productid);
- $productid = str_replace("</ul>", "", $productid);
- $productid = ltrim($productid);
- $productid = rtrim($productid);
- $productid = mysqli_real_escape_string($con, $productid);
- $sql = "UPDATE `product` SET `productid` = '$productid' WHERE `upc` = ".$row['upc'];
- mysqli_query($con, $sql);
- };
- for($i=1; $i<7; $i++){
- $theimage = $row["image$i"];
- if ($theimage){
- $theimage = trim($theimage);
- $theimage = ltrim($theimage);
- $theimage = rtrim($theimage);
- $theimage = preg_replace('/(\s\s+|\t|\n)/', ' ', $theimage);
- $context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n')));
- $img = @file_get_contents($theimage,false,$context);
- if ($img === false) {
- echo "</BR>FAILED GET URL: ".$row['upc']." - ".$theimage;
- } else {
- $imgtitle = str_replace(" ", "-", $row['title']);
- $imgtitle = str_replace("/", "", $imgtitle);
- if (!is_dir("./images/".$row['upc']."/")){mkdir("./images/".$row['upc']."/");};
- $content = @file_put_contents("./images/".$row['upc']."/".$imgtitle."-$i.jpg", $img);
- if ($content === false) {echo "</BR>FAILED TO PUT IMAGE: ".$row['upc']." - ".$theimage;}
- }
- }}
- echo "<script type='text/javascript'>
- document.getElementById('timer').innerHTML = $counter;
- </script>";
- }
- }
- $time_end = microtime(true);
- function formatPeriod($endtime, $starttime)
- {
- $duration = $endtime - $starttime;
- $hours = (int) ($duration / 60 / 60);
- $minutes = (int) ($duration / 60) - $hours * 60;
- $seconds = (int) $duration - $hours * 60 * 60 - $minutes * 60;
- return ($hours == 0 ? "00":$hours) . ":" . ($minutes == 0 ? "00":($minutes < 10? "0".$minutes:$minutes)) . ":" . ($seconds == 0 ? "00":($seconds < 10? "0".$seconds:$seconds));
- }
- echo '</br><b>Total Execution Time:</b> '.formatPeriod($time_end, $time_start);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement