Skip to content

Instantly share code, notes, and snippets.

@pgrimaud
Created November 16, 2017 12:59
Show Gist options
  • Save pgrimaud/15e53642e022bf21a2bb79766c2acc30 to your computer and use it in GitHub Desktop.
Save pgrimaud/15e53642e022bf21a2bb79766c2acc30 to your computer and use it in GitHub Desktop.
Automatically check iPhone X inventory in Apple Stores
<?php
/**
* https://www.apple.com/fr/ only
* For other languages, change uri of file_get_contents and change value of var $noStock
*/
$models = [
'iPhone X 64Go Silver' => 'MQAD2ZD/A',
'iPhone X 256Go Silver' => 'MQAG2ZD/A',
'iPhone X 64Go Space Gray' => 'MQAC2ZD/A',
'iPhone X 256Go Space Gray' => 'MQAF2ZD/A',
];
$modelsAvailable = [];
foreach ($models as $model => $ref) {
$file = file_get_contents('https://www.apple.com/fr/shop/retail/pickup-message?pl=true&parts.0=' . $ref . '&location=75001&time=' . time());
$data = json_decode($file, JSON_OBJECT_AS_ARRAY);
$noStock = 'Non disponible aujourd’hui dans [X] magasins à proximité.';
if ($data['body']['notAvailableNearby'] !== $noStock) {
$modelsAvailable[] = $model;
}
}
if ($modelsAvailable) {
$content = '';
foreach ($modelsAvailable as $model) {
$content .= $model . PHP_EOL;
}
$headers = 'From: iphone@yourserver.com' . "\r\n" .
'Reply-To: iphone@yourserver.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail('youremail@test.com', 'Some iPhone X are available!', $content, $headers);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment