Last active
December 30, 2015 19:29
-
-
Save tomnomnom/7874970 to your computer and use it in GitHub Desktop.
Hacky FTTC Check Script
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'; // You can find your Address ID using this: https://gist.github.com/TomNomNom/7875919 | |
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){ | |
$infinityAvailable = true; | |
} | |
$message .= " #{$i} {$lineType->serviceLineType}\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
You might want to factor in readyDate or risk getting your hopes up with a false positive, like I did :D
http://www.productsandservices.bt.com/consumerProducts/v1/productAvailability.do?telephone=01274885354&format=json is an example