Skip to content

Instantly share code, notes, and snippets.

@sergix44
Created August 24, 2019 17:22
Show Gist options
  • Save sergix44/440b9711ba4656658e06fe29d3199b47 to your computer and use it in GitHub Desktop.
Save sergix44/440b9711ba4656658e06fe29d3199b47 to your computer and use it in GitHub Desktop.
<?php
# -- config --
$INTERVAL = 5; // sec
$CODE = '1801sk20';
$COUNTRY = 'it';
$BUY_URL = "https://www.kimsufi.com/it/ordine/kimsufi.xml?reference=$CODE";
# ------------
function notify() {
global $CODE, $BUY_URL;
$url = 'https://api.telegram.org/botTOKEN_HERE/sendMessage';
$options = [
'http' => [
'method' => 'POST',
'header' => "Content-Type:application/x-www-form-urlencoded\r\n",
'content' => http_build_query(['chat_id' => CHAT_ID_HERE, 'text' => "Available $CODE\n$BUY_URL"]),
],
];
$context = stream_context_create($options);
file_get_contents($url, false, $context);
}
function check($code, $country) {
$json = json_decode(file_get_contents("https://www.ovh.com/engine/api/dedicated/server/availabilities?country=$country"));
foreach ($json as $server) {
if ($server->hardware === $code) {
$available = false;
foreach ($server->datacenters as $location) {
if ($location->availability !== 'unavailable') {
$available = true;
break;
}
}
if ($available) {
notify();
}
}
}
}
for ($i = 0; $i < (60/$INTERVAL); $i++) {
check($CODE, $COUNTRY);
sleep($INTERVAL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment