Skip to content

Instantly share code, notes, and snippets.

@markbiek
Created August 17, 2020 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markbiek/02737438c2a8ba56855e07ba53640cf8 to your computer and use it in GitHub Desktop.
Save markbiek/02737438c2a8ba56855e07ba53640cf8 to your computer and use it in GitHub Desktop.
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\DomCrawler\Crawler;
use Twilio\Rest\Client;
$sid = 'ABC123';
$token = '321CBA';
$client = new Client($sid, $token);
try {
$url = "https://my/scheduling/url";
$html = file_get_contents($url);
$crawler = new Crawler($html);
header('Content-Type: text/plain');
$found = false;
$nodes = $crawler->filter('body div.media');
foreach ($nodes as $node) {
$text = strtolower($node->textContent);
$text = str_replace(["\n","\r"], "", $text);
if (strpos($text, "no openings available") === false) {
$found = true;
// There might be an opening!
$body = "$text\n$url";
$client->messages->create('+15551212', [
'from' => '+15551212',
'body' => $body,
]);
}
}
if (!$found) {
echo "no openings available";
}
}catch (\Exception $e) {
$client->messages->create('+15551212', [
'from' => '+15551212',
'body' => "Error checking schedule: " . $e->getMessage(),
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment