Skip to content

Instantly share code, notes, and snippets.

@raoulduke
Last active February 3, 2021 22:23
Show Gist options
  • Save raoulduke/dfd978ee51ae210a91892ef0b8d8900c to your computer and use it in GitHub Desktop.
Save raoulduke/dfd978ee51ae210a91892ef0b8d8900c to your computer and use it in GitHub Desktop.
Track FitnessDepot inventory by SKU
<?php
$sku = 'PBSEXP50';
$url = 'https://www.fitnessdepot.ca/WebService/store-inventory.php?store_id=6&price=549.88&sku=' . $sku;
// List of nodes I don't want to check, some store inventory is not up to date
$ignoreNodes = [
'Oakville',
'Call or Email to Order1-877-776-8547ecommerce@fitnessdepot.ca'
];
$foundNodes = [];
$inStock = false;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
// report an error
exit(1);
}
$doc = new DOMDocument();
@$doc->loadHTML($response); //suppress warnings due to invalid HTML
$trs = $doc->getElementsByTagName('tr');
foreach ($trs as $tr) {
$tds = $tr->getElementsByTagName('td');
if (!in_array(@$tds[0]->nodeValue, $ignoreNodes) && @$tds[1]->nodeValue == "In Stock") {
$inStock = true;
$foundNodes[] = $tds[0]->nodeValue;
}
}
if ($inStock) {
$message = "SKU: {$sku}\r\nFound inventory at the following locations: " . implode(', ', $foundNodes) . "\r\n";
$ret = mail(getenv('PERSONAL_EMAIL'), 'FitnessDepot Inventory', $message);
}
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment