внёс первые изменения
This commit is contained in:
54
scripts/employees_parser.php
Normal file
54
scripts/employees_parser.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
use SvedenParser\Color;
|
||||
use SvedenParser\Parser\EmployeesManager;
|
||||
use SvedenParser\Parser\EmployeesRepository;
|
||||
use SvedenParser\Exception\HtmlException;
|
||||
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 EmployeesManager();
|
||||
$sites = $manager->getSites();
|
||||
// $sites = Yaml::parse(file_get_contents(SVEDEN_PARSER . "/data/remains.yaml"));
|
||||
|
||||
$start = 0; $end = count($sites);
|
||||
|
||||
for ($i = $start; $i < $end; $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 . " не обнаружен. Дозапись в базу не требуется");
|
||||
}
|
||||
|
||||
$employees = Yaml::parse(file_get_contents(Repository::FILE_ADD_RECORDING));
|
||||
$repository = new EmployeesRepository();
|
||||
$repository->insert($employees);
|
||||
|
||||
Printer::println("Дозапись выполнена!", Color::BLUE);
|
||||
} catch (\Exception $e) {
|
||||
Printer::println($e->getMessage(), Color::RED);
|
||||
}
|
Reference in New Issue
Block a user