Skip to content

Instantly share code, notes, and snippets.

@crashmax-dev
Last active May 21, 2021 14:27
Show Gist options
  • Save crashmax-dev/f423f02ce017f8b878833a59ff999999 to your computer and use it in GitHub Desktop.
Save crashmax-dev/f423f02ce017f8b878833a59ff999999 to your computer and use it in GitHub Desktop.
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Credentials: false');
header("Access-Control-Allow-Origin: *");
require "../vendor/autoload.php";
use PHPHtmlParser\Dom;
$dom = new Dom;
$dom->load('https://eteenindus.mnt.ee/public/vabadSoidueksamiajad.xhtml');
$tbody = $dom->find('tbody > tr');
if (count($tbody) > 0) {
$thead = $dom->find('.eksam-ajad-uuendatud > span');
$last_update = explode(": ", $thead->innerHtml)[1];
$data = [];
for ($i = 0; $i < count($tbody); $i++) {
$location = $tbody[$i]->find('td > span')->innerHtml;
$data[$location] = array(
$tbody[$i]->find('td')[2]->innerHtml,
$tbody[$i]->find('td')[3]->innerHtml,
$tbody[$i]->find('td')[4]->innerHtml,
);
}
echo json_encode(array(
'ok' => true,
'last_update' => $last_update,
'data' => $data));
} else {
echo json_encode(array('ok' => false));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment