Created
August 17, 2020 20:14
-
-
Save markbiek/02737438c2a8ba56855e07ba53640cf8 to your computer and use it in GitHub Desktop.
This file contains 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
<?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