Skip to content

Instantly share code, notes, and snippets.

@eyecatchup
Last active February 3, 2017 03:54
Show Gist options
  • Save eyecatchup/bd88d334fb14cc4fdadccbc6fef0d53b to your computer and use it in GitHub Desktop.
Save eyecatchup/bd88d334fb14cc4fdadccbc6fef0d53b to your computer and use it in GitHub Desktop.
Cronjob to send a notification AS SOON as the Android 7.1.2 beta is available for the Nexus 6P.
<?php
/**
* Android 7.1.2 beta for Nexus 6P email alert cronjob (Note: Requires PHP /w curl and being able to send mails!)
*
* 1. Download this script.
* 2. Set the value for the constant NOTIFY_MAIL_ADDRESS below to your email address.
* 3. Create a new cronjob (for a Win/Xampp alternative see: http://stackoverflow.com/a/4231634/624466). On your console, type:
* crontab -e
* 4. Paste the following (adjust script/logfile path):
* 0 * * * * php /absolute/path/to/script.php >> /absolute/path/to/cronjob.log
* 5. Exit crontab and you're all set. You'll get an email as soon as the Android 7.1.2 beta OTA image is available for the Nexus 6P.
*/
// CHANGE THIS TO YOUR EMAIL ADDRESS !!!
const NOTIFY_MAIL_ADDRESS = '[email protected]';
// NO NEED FOR CHANGES BELOW
function getHttpResponse($url) {
$curl = curl_init($url);
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_MAXREDIRS => 3,
CURLOPT_SSL_VERIFYPEER => 0
]);
$resp = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
return 200 == (int)$code ? $resp : false;
}
function sendAlert($url) {
$msg = 'Strike! The Android 7.1.2 beta OTA image for the Nexus 6P is now online, too: ' . $url;
mail(NOTIFY_MAIL_ADDRESS, 'Android 7.1.2 for Nexus 6P OTA Alert', $msg);
echo $msg . PHP_EOL;
}
function checkAngler($str) {
if (!$str || !is_string($str) || 0 == strlen($str)) {
return false;
}
preg_match('/angler(.*?)\.zip/um', $str, $match);
if (isset($match[1])) {
$otaUrlRoot = 'http://storage-download.googleapis.com/androiddevelopers/shareables/preview/';
$otaFile = sprintf('angler%s.zip', $match[1]);
$otaUrl = $otaUrlRoot . $otaFile;
return $otaUrl;
}
return false;
}
$betaUrl = 'https://developer.android.com/preview/download-712.html';
$str = getHttpResponse($betaUrl);
$otaUrl = checkAngler($str);
if (false !== $otaUrl) {
sendAlert($otaUrl);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment