Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Checks the Nescafe Dolce Gusto website to see if a certain product is in stock
# Checks the Nescafe Dolce Gusto website to see if your pods are back in stock
# by Laurie Denness
# This program sends an email to THIS ADDRESS:
$email = "";
# When your chosen coffee pod (specify on the command line) comes back into stock.
# e.g. php coffeeinstock.php 7613032349523_08
# Some colours
$red = "\033[31m";
$white = "\033[0m";
$yellow = "\033[1;33m";
$blue = "\033[34m";
$green = "\033[32m";
$productid = $argv[1];
if (!$productid) {
logline("{$red}ERR: {$white}A product ID is required to check, get this from the URL from the DG website");
logline("E.g.: php coffeeinstock.php 7613032349523_08");
$url = "{$productid}";
while (true) {
# go into a loop. The program exits and sends an email when it's in stock, otherwise
# it tries and tries again.
if (false == ($html = file_get_contents($url))) {
# this HTTP GET failed.
logline("{$red}ERR: {$white}This fetch failed. Retrying.");
} else {
# search to make sure the product actually exists
if (strpos($html,"Error")) {
logline("{$yellow}WARN: {$white}An error occured. Does that product exist?");
# search for "Out of Stock"
if (stripos($html, "Out of Stock") === false) {
logline("{$green}YAY: {$white}Product is in stock!");
logline("{$blue}INFO: {$white}Sending email to {$email}");
# send an email, rejoice, etc
if (sendmail("Great news, your coffee pods product {$productid} are now in stock!", $email, "Your coffee pods are in stock!")) {
logline("{$green}OK: {$white} Email sent! Goodbye.");
} else {
logline("{$red}ERR: {$white} Email sending failed.");
} else {
logline("{$yellow}WARN: {$white}Product is not in stock. Retrying.");
logline("{$blue}INFO: {$white}Sleeping 1800 seconds...");
function logline($message) {
echo date(DATE_RFC822) . " " . $message . "\n";
function sendmail($message, $emailaddr, $subject) {
$headers = "From: " . $email . "\r\n";
$headers .= 'Reply-To: ' . $emailaddr ."\r\n";
$headers .= "X-Mailer: PHPCoffeeScript\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
if (mail($emailaddr, $subject, $message, $headers)) {
return true;
} else {
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.