sveden-parser/scripts/script.php

64 lines
1.8 KiB
PHP

<?php
use SvedenParser\ContingentParser\ContingentFacade;
require_once __DIR__ . "/vendor/autoload.php";
function getErrorSites($file)
{
$result = array();
$data = file($file);
foreach ($data as $value) {
$value = explode(' ', $value);
$result[] = $value[2];
}
return $result;
}
function emptySites($sourceAll, $remains) {
$result = array();
foreach ($sourceAll as $every) {
if (in_array($every['org_id'], $remains)
&& $every['site'] === ''
) {
$result[] = $every['org_id'];
}
}
return $result;
}
function write($file, $source)
{
global $sourceAll;
foreach($sourceAll as $s) {
if (in_array($s['org_id'], $source)) {
file_put_contents($file, implode(' ', $s).PHP_EOL, FILE_APPEND);
}
}
}
$facade = new ContingentFacade();
$sourceAll = $facade->getSites();
$all = array_column($sourceAll, 'org_id'); // все организации
$inBase = $facade->getOrgInOpendata(); // организации уже в базе
$httpAndHtml = array_values(array_diff($all, $inBase));
echo "ALL". PHP_EOL;
print_r($httpAndHtml);
$http = getErrorSites('log/http-curl.log');
$html = getErrorSites('log/html.log');
$http = array_values(array_diff($httpAndHtml, $html));
write('sites-html.log', $html);
write('sites-http.log', $http);
// echo "HTML". PHP_EOL;
// print_r($html);
// echo "HTTP". PHP_EOL;
// print_r($http);
// echo "REMAINS". PHP_EOL;
// $remains = array_values(array_diff($httpAndHtml, array_merge($html, $http)));
// print_r($remains);
// echo "EMPTY". PHP_EOL;
// $empty = emptySites($sourceAll, $remains);
// print_r($empty);
// // $fall = array_values(array_diff($remains, $empty));
// // print_r($fall);
// write('sites-html.log', $html);
// write('sites-http.log', $http);