2024-09-03 15:41:45 +03:00
|
|
|
|
<?php
|
|
|
|
|
namespace ContingentParser;
|
|
|
|
|
|
|
|
|
|
use ContingentParser\Database\DatabaseFacade;
|
|
|
|
|
use ContingentParser\Http\HttpClientFacade;
|
|
|
|
|
use ContingentParser\Http\UrlBuilder;
|
|
|
|
|
use ContingentParser\Logger\HtmlLogger;
|
|
|
|
|
use ContingentParser\Parser\ContingentFacade;
|
|
|
|
|
|
|
|
|
|
class Facade
|
|
|
|
|
{
|
|
|
|
|
private DatabaseFacade $databaseFacade;
|
|
|
|
|
private HttpClientFacade $httpClientFacade;
|
|
|
|
|
private ContingentFacade $contingentFacade;
|
|
|
|
|
private UrlBuilder $urlBuilder;
|
|
|
|
|
private HtmlLogger $htmlLogger;
|
|
|
|
|
/**
|
|
|
|
|
* Конструктор
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->databaseFacade = new DatabaseFacade();
|
|
|
|
|
$this->httpClientFacade = new HttpClientFacade();
|
|
|
|
|
$this->urlBuilder = new UrlBuilder();
|
|
|
|
|
$this->contingentFacade = new ContingentFacade();
|
|
|
|
|
$this->htmlLogger = new HtmlLogger('log/html.log');
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получить массив сайтов
|
|
|
|
|
* @param array $params
|
|
|
|
|
* Массив сайтов, у которых нужны обновиленные URL
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getSites(array $params = []) : array
|
|
|
|
|
{
|
|
|
|
|
if (empty($params)) {
|
|
|
|
|
return $this->databaseFacade->getSitesFromNiimko();
|
|
|
|
|
} else {
|
|
|
|
|
return $this->databaseFacade->getSitesFromMiccedu($params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Cобирает из микроразметки данные таблицы
|
|
|
|
|
* "Информация о численности обучающихся" в разделе "Образование"
|
|
|
|
|
* @param array $site
|
|
|
|
|
* Сайт содержащий id организации и URL
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function collectDataFromContingent(array $site) : void
|
|
|
|
|
{
|
|
|
|
|
list('org_id' => $orgId, 'site' => $url) = $site;
|
|
|
|
|
// Нет URL сайта вуза
|
|
|
|
|
if (empty($site)) {
|
|
|
|
|
// $httpLogger->log($orgId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Уже в базе
|
|
|
|
|
if (in_array($orgId, $this->databaseFacade->universities())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$url = $this->urlBuilder->build($url);
|
2024-09-04 16:12:03 +03:00
|
|
|
|
Printer::println(implode(' ', $site), 'green');
|
2024-09-03 15:41:45 +03:00
|
|
|
|
$html = $this->httpClientFacade->processEducationContingentSites(
|
|
|
|
|
$url,
|
|
|
|
|
$site
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$contingent = $this->contingentFacade->getContingent(
|
|
|
|
|
$html,
|
|
|
|
|
$this->databaseFacade->specialties(),
|
|
|
|
|
$orgId
|
|
|
|
|
);
|
|
|
|
|
|
2024-09-04 16:12:03 +03:00
|
|
|
|
if ($contingent) {
|
|
|
|
|
// $contingent = $this->contingentFacade->getContingentFromLink($html);
|
|
|
|
|
// if ($contingent) {
|
|
|
|
|
Printer::println("No result", 'red');
|
|
|
|
|
$this->htmlLogger->log("$orgId $url");
|
|
|
|
|
// }
|
2024-09-03 15:41:45 +03:00
|
|
|
|
} else {
|
|
|
|
|
if ($this->contingentFacade->isValidContingent($contingent)) {
|
|
|
|
|
// Заносим в базу
|
2024-09-04 16:12:03 +03:00
|
|
|
|
Printer::print_r($contingent, 'blue');
|
|
|
|
|
$this->databaseFacade->insertContingent($contingent);
|
2024-09-03 15:41:45 +03:00
|
|
|
|
} else {
|
|
|
|
|
$this->htmlLogger->log("$orgId $url");
|
2024-09-04 16:12:03 +03:00
|
|
|
|
Printer::println("No result", 'red');
|
2024-09-03 15:41:45 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-04 16:12:03 +03:00
|
|
|
|
Printer::println();
|
2024-09-03 15:41:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getExclusionSites(string $path) : array
|
|
|
|
|
{
|
|
|
|
|
$logs = file($path);
|
|
|
|
|
$result = [];
|
|
|
|
|
foreach ($logs as $log) {
|
|
|
|
|
$data = explode(' ', $log);
|
|
|
|
|
$result[] = [
|
|
|
|
|
'org_id' => $data[2],
|
|
|
|
|
'site' => $data[3] ? $data[3] : ''
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
}
|