2024-10-10 08:38:24 +03:00
|
|
|
<?php
|
|
|
|
use SvedenParser\Color;
|
2024-12-01 11:23:31 +03:00
|
|
|
use SvedenParser\Exception\HtmlException;
|
2024-10-10 11:51:24 +03:00
|
|
|
use SvedenParser\PriemParser\PriemManager;
|
2024-10-10 13:35:52 +03:00
|
|
|
use SvedenParser\PriemParser\PriemRepository;
|
2024-10-10 08:38:24 +03:00
|
|
|
use SvedenParser\Printer;
|
2024-10-10 13:35:52 +03:00
|
|
|
use SvedenParser\Repository;
|
2024-10-10 08:38:24 +03:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2024-10-10 11:51:24 +03:00
|
|
|
|
|
|
|
define('SVEDEN_PARSER', '/home/developer/sveden_parser');
|
|
|
|
|
|
|
|
require_once SVEDEN_PARSER . "/vendor/autoload.php";
|
|
|
|
|
2024-12-01 11:23:31 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-10 11:51:24 +03:00
|
|
|
$manager = new PriemManager();
|
2024-12-01 11:23:31 +03:00
|
|
|
// $sites = $manager->getSites();
|
|
|
|
// $sites = Yaml::parse(file_get_contents(SVEDEN_PARSER . "/data/remains.yaml"));
|
2024-10-10 11:51:24 +03:00
|
|
|
|
2024-10-10 13:35:52 +03:00
|
|
|
$start = 0; $end = count($sites);
|
2024-10-10 11:51:24 +03:00
|
|
|
|
|
|
|
for ($i = $start; $i < $end; $i++) {
|
2024-12-01 11:23:31 +03:00
|
|
|
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);
|
|
|
|
}
|
2024-10-10 11:51:24 +03:00
|
|
|
}
|
2024-10-10 13:35:52 +03:00
|
|
|
Printer::println();
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!file_exists(Repository::FILE_ADD_RECORDING)) {
|
2024-12-01 11:23:31 +03:00
|
|
|
throw new Exception("Файл " . Repository::FILE_ADD_RECORDING . " не обнаружен. Дозапись в базу не требуется");
|
2024-10-10 13:35:52 +03:00
|
|
|
}
|
|
|
|
|
2024-12-01 11:23:31 +03:00
|
|
|
$priem = Yaml::parse(file_get_contents(Repository::FILE_ADD_RECORDING));
|
|
|
|
$repository = new PriemRepository();
|
|
|
|
$repository->insert($priem);
|
2024-10-10 13:35:52 +03:00
|
|
|
|
2024-12-01 11:23:31 +03:00
|
|
|
Printer::println("Дозапись выполнена!", Color::BLUE);
|
2024-10-10 13:35:52 +03:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
Printer::println($e->getMessage(), Color::RED);
|
|
|
|
}
|