Last active
August 29, 2015 14:11
-
-
Save jaydlawrence/295346b45ca5269e1e5a to your computer and use it in GitHub Desktop.
A short PHP script to notify me via PushBullet when the Nexus 6 64GB White becomes available for sale on the UK Google Play store
This file contains hidden or 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
#!/usr/bin/php | |
<?php | |
$url = "https://play.google.com/store/devices/details/Nexus_6_64_GB_Cloud_White?id=nexus_6_white_64gb"; | |
//$url = "https://play.google.com/store/devices/details/Nexus_6_64_GB_Midnight_Blue?id=nexus_6_blue_64gb"; | |
//$url = "https://play.google.com/store/devices/details/Nexus_6_32_GB_Midnight_Blue?id=nexus_6_blue_32gb"; | |
$opts = array('http' => | |
array( | |
'method' => 'GET', | |
'header' => array( | |
"authority:play.google.com", | |
"path:/store/devices/details/Nexus_6_64_GB_Cloud_White?id=nexus_6_white_64gb", | |
"accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", | |
"accept-language:en-GB,en;q=0.8", | |
"cache-control:max-age=0", | |
"user-agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36", | |
), | |
) | |
); | |
$context = stream_context_create($opts); | |
$count = 0; | |
while (true) { | |
$count++; | |
$page = file_get_contents($url, false, $context); | |
$dom = new DOMDocument; | |
@$dom->loadHTML($page); | |
$finder = new DOMXPath($dom); | |
$className="details-actions"; | |
$nodes = $finder->query("//*[contains(@class, '$className')]"); | |
/** @var DOMElement $node */ | |
foreach ($nodes as $node) { | |
//look for data-availability attribute inside this node | |
/** @var DOMNodeList $childNodeList */ | |
$childNodeList = $finder->query("*[@data-availability]", $node); | |
/** @var DOMElement $childNode */ | |
foreach ($childNodeList as $childNode) { | |
if ($childNode->getAttribute('data-availability') == "AVAILABLE") { | |
echo "now available"; | |
$data = array( | |
"type" => "note", | |
"title" => 'AVAILABLE!!! - Nexus 6 64GB White', | |
"body" => 'AVAILABLE!!! - Nexus 6 64GB White' . "\r\n" . $url | |
); | |
$dataString = json_encode($data); | |
$pushBulletToken = "<yourtokenhere>"; | |
$ch = curl_init('https://api.pushbullet.com/v2/pushes'); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_USERPWD, $pushBulletToken); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($dataString)) | |
); | |
$result = curl_exec($ch); | |
var_dump($result); | |
curl_close ($ch); | |
exit; | |
} | |
} | |
} | |
if ($count % 60 == 0) { | |
echo $count . " Not - available. Sleeping - " . time() . "\n"; | |
} | |
sleep(5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment