внёс первые изменения

This commit is contained in:
2024-12-01 11:23:31 +03:00
parent e3bedc2bdf
commit d583c56dfa
47 changed files with 10658 additions and 315 deletions

View File

@ -1,46 +1,54 @@
<?php
use SvedenParser\Color;
use SvedenParser\Exception\HtmlException;
use SvedenParser\PriemParser\PriemManager;
use SvedenParser\PriemParser\PriemRepository;
use SvedenParser\Printer;
use SvedenParser\Repository;
use Symfony\Component\Yaml\Yaml;
define('SVEDEN_PARSER', '/home/developer/sveden_parser');
require_once SVEDEN_PARSER . "/vendor/autoload.php";
if (file_exists(Repository::FILE_ADD_RECORDING)) {
Printer::println("Обнаружен файл " . Repository::FILE_ADD_RECORDING, Color::RED);
Printer::print("Продолжить y/n? ", Color::BLUE);
$action = trim(fgets(STDIN));
if ($action !== 'y') {
exit;
}
}
$manager = new PriemManager();
$sites = $manager->getSites();
// $sites = Yaml::parse(file_get_contents(dirname(__FILE__) ."/sites.yaml"));
// $sites = $manager->getSites();
// $sites = Yaml::parse(file_get_contents(SVEDEN_PARSER . "/data/remains.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);
$manager->collectData($sites[--$i]);
try {
Printer::print(++$i . ". ", Color::GREEN);
$manager->collectData($sites[--$i]);
} catch (HtmlException $e) {
$e->write($sites[$i]);
file_put_contents(SVEDEN_PARSER . '/log/doc.log', implode(' ', $sites[$i]) . PHP_EOL, FILE_APPEND);
} catch (\Exception $e) {
Printer::println($e->getMessage(), Color::RED);
}
}
Printer::println();
try {
if (!file_exists(Repository::FILE_ADD_RECORDING)) {
throw new Exception(
"Файл " . Repository::FILE_ADD_RECORDING
. " не обнаружен. Дозапись в базу не требуется"
);
throw new Exception("Файл " . Repository::FILE_ADD_RECORDING . " не обнаружен. Дозапись в базу не требуется");
}
$priem = Yaml::parse(
file_get_contents(SVEDEN_PARSER . '/' . Repository::FILE_ADD_RECORDING)
);
$databaseFacade = new PriemRepository();
$databaseFacade->insert($priem);
$priem = Yaml::parse(file_get_contents(Repository::FILE_ADD_RECORDING));
$repository = new PriemRepository();
$repository->insert($priem);
Printer::println("Дозапись выполнена!", Color::BLUE);
Printer::println("Дозапись выполнена!", Color::BLUE);
} catch (\Exception $e) {
Printer::println($e->getMessage(), Color::RED);
exit(0);
}