Skip to content

Instantly share code, notes, and snippets.

@iMartyn
Forked from tomnomnom/fttc-check.php
Last active December 30, 2015 19:39
Show Gist options
  • Save iMartyn/7875913 to your computer and use it in GitHub Desktop.
Save iMartyn/7875913 to your computer and use it in GitHub Desktop.
<?php
// Change me
const ADDRESS_ID = 'Gold|StringOfAlphas|MY|HouseNumber'; // Pull from the BT checker with a network inspector :)
const TO_EMAIL = 'me@example.com';
const FROM_EMAIL = 'server@example.com';
// Don't change me
const SERVICE_URL = 'http://www.productsandservices.bt.com/consumerProducts/v1/productAvailability.do';
$query = http_build_query(array(
'addressId' => ADDRESS_ID,
'format' => 'json'
));
$r = file_get_contents(SERVICE_URL.'?'.$query);
$s = json_decode($r);
if (!$s){
sendMail("FTTC Check Script Failed", "Failed to parse JSON");
exit(1);
}
$message =
"Exchange name: {$s->exchangeName}\r\n".
"Service types available: \r\n";
$infinityAvailable = false;
foreach ($s->serviceLineTypes as $i => $lineType){
if ($lineType->infinity && property_exists($lineType, 'readyDate') &! empty($lineType->readyDate)){
// Check that the date is not futuristic!
if (strtotime($lineType->readyDate) <= time()) {
$infinityAvailable = true;
}
} elseif ($lineType->infinity) {
$infinityAvailable = true;
}
$message .= " #{$i} {$lineType->serviceLineType}";
if (property_exists($lineType, 'readyDate') &! empty($lineType->readyDate)) {
$message .= " (from {$lineType->readyDate})\r\n";
} else {
$message .= "\r\n";
}
}
if ($infinityAvailable){
sendMail("FTTC Available!", $message);
} else {
sendMail("FTTC Not Available", $message);
}
exit(0);
/////////
// Lib //
/////////
function sendMail($subject, $body){
$headers = 'From: ' .FROM_EMAIL. "\r\n";
mail(TO_EMAIL, $subject, $body, $headers);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment