Поменял структуру проекта для расширения задачи с приемом
This commit is contained in:
31
scripts/add_recording.php
Normal file
31
scripts/add_recording.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* При ошибке в запросе к БД. Распарсингованные данные
|
||||
* сохраняются в yaml-файле. Скрипт парсит этот файл и заносит в БД
|
||||
*/
|
||||
use ContingentParser\Color;
|
||||
use ContingentParser\Database\DatabaseFacade;
|
||||
use ContingentParser\Printer;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
require_once __DIR__ . "/vendor/autoload.php";
|
||||
|
||||
try {
|
||||
if (!file_exists(DatabaseFacade::FILE_ADD_RECORDING)) {
|
||||
throw new Exception(
|
||||
"Файл " . DatabaseFacade::FILE_ADD_RECORDING
|
||||
. " не обнаружен. Дозапись в базу не требуется"
|
||||
);
|
||||
}
|
||||
|
||||
$contingent = Yaml::parse(
|
||||
file_get_contents(__DIR__ . '/' . DatabaseFacade::FILE_ADD_RECORDING)
|
||||
);
|
||||
$databaseFacade = new DatabaseFacade();
|
||||
$databaseFacade->insertContingent($contingent);
|
||||
|
||||
Printer::println("Дозапись выполнена!", Color::BLUE);
|
||||
} catch (\Exception $e) {
|
||||
Printer::println($e->getMessage(), Color::RED);
|
||||
exit(0);
|
||||
}
|
23
scripts/contingent_parser.php
Normal file
23
scripts/contingent_parser.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use SvedenParser\Color;
|
||||
use SvedenParser\ContingentParser\ContingentFacade;
|
||||
use SvedenParser\Printer;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
require_once __DIR__ . "/vendor/autoload.php";
|
||||
|
||||
$facade = new ContingentFacade();
|
||||
$sites = $facade->getSitesFromLog('sites-http.log');
|
||||
// $sites = $facade->getSites();
|
||||
// $sites = Yaml::parse(file_get_contents(dirname(__FILE__) ."/sites.yaml"));
|
||||
|
||||
$start = 0; $end = count($sites);
|
||||
// $start = 0; $end = (int)(count($sites) / 2);
|
||||
// $start = (int)(count($sites) / 2); $end = count($sites);
|
||||
|
||||
for ($i = $start; $i < $end; $i++) {
|
||||
Printer::print(++$i . ". ", Color::GREEN);
|
||||
$facade->collectDataFromContingent($sites[--$i]);
|
||||
}
|
||||
Printer::println();
|
||||
// require __DIR__ . "/add_recording.php";
|
5
scripts/priem_parser.php
Normal file
5
scripts/priem_parser.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
use SvedenParser\Color;
|
||||
use SvedenParser\Printer;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
require_once __DIR__ . "/vendor/autoload.php";
|
64
scripts/script.php
Normal file
64
scripts/script.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?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);
|
Reference in New Issue
Block a user