-
-
Save iMartyn/7875913 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Change me | |
const ADDRESS_ID = 'Gold|StringOfAlphas|MY|HouseNumber'; // Pull from the BT checker with a network inspector :) | |
const TO_EMAIL = '[email protected]'; | |
const FROM_EMAIL = '[email protected]'; | |
// 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