Решена проблема кодировок
This commit is contained in:
60
app/app.php
60
app/app.php
@ -5,6 +5,7 @@ use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Exception\ServerException;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
|
||||
use App\Library\ContingentParser;
|
||||
use App\Library\Database;
|
||||
@ -30,7 +31,11 @@ $dbNiimko = new Database(
|
||||
$dbconfig['user'],
|
||||
$dbconfig['password']
|
||||
);
|
||||
|
||||
$builder = new GenericBuilder();
|
||||
|
||||
// select kod as org_id, site from niimko.s_vuzes
|
||||
// where ootype = 'vuz' and deleted = 'n' and fake = 'n'
|
||||
$params = ['vuz', 'n', 'n'];
|
||||
$query = $builder->select()
|
||||
->setTable('s_vuzes')
|
||||
@ -43,12 +48,33 @@ $query = $builder->select()
|
||||
$sql = $builder->write($query);
|
||||
$sites = $dbNiimko->executeQuery($sql, $params);
|
||||
|
||||
// select id, kod from niimko.s_specs where oopkodes = 'gos3p'
|
||||
$params = ['gos3p'];
|
||||
$query = $builder->select()
|
||||
->setTable('s_specs')
|
||||
->setColumns(['id', 'kod'])
|
||||
->where()
|
||||
->equals('oopkodes','gos3p')
|
||||
->end();
|
||||
$sql = $builder->write($query);
|
||||
$specializations = $dbNiimko->executeQuery($sql, $params);
|
||||
|
||||
// print_r($sites);
|
||||
// print_r($specializations);
|
||||
|
||||
// $sites = [ ['site' => "http://marsu.ru"], ['site' => "http://voenmeh.ru"], ['site' => "http://angtu.ru"] ];
|
||||
$i = 0;
|
||||
$succes = 0;
|
||||
foreach ($sites as $site) {
|
||||
try {
|
||||
$client = new Client();
|
||||
$client = new Client([
|
||||
RequestOptions::ALLOW_REDIRECTS => [
|
||||
'max' => 10, // allow at most 10 redirects.
|
||||
'strict' => true, // use "strict" RFC compliant redirects.
|
||||
'referer' => true, // add a Referer header
|
||||
'track_redirects' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$route = "{$site['site']}/sveden/education/";
|
||||
$route = str_replace("http","https", $route);
|
||||
@ -61,7 +87,28 @@ foreach ($sites as $site) {
|
||||
$html = $response->getBody()->getContents();
|
||||
$parser = new ContingentParser($html, '//tr[@itemprop="eduChislen"]//');
|
||||
$contingent = $parser->getDataTable();
|
||||
|
||||
// Добавляем поле spec_id по spec_code
|
||||
foreach ($contingent as $key => $con) {
|
||||
$needle = $con['spec_code'];
|
||||
foreach ($specializations as $spec) {
|
||||
if ($needle == $spec['kod']) {
|
||||
$contingent[$key]['spec_id'] = $spec['id'];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$contingent[$key]['spec_id'] = null;
|
||||
}
|
||||
|
||||
// Добавляем поле org_id
|
||||
foreach ($contingent as $key => $spec) {
|
||||
$contingent[$key]['org_id'] = $site['org_id'];
|
||||
}
|
||||
|
||||
print_r($contingent);
|
||||
if ($response->getStatusCode() == 200 && !empty($contingent)){
|
||||
print("Succes: ".++$succes."\n");
|
||||
}
|
||||
} catch (ClientException $e) {
|
||||
$response = $e->getCode();
|
||||
} catch (RequestException $e) {
|
||||
@ -73,17 +120,6 @@ foreach ($sites as $site) {
|
||||
}
|
||||
}
|
||||
|
||||
// $specializations = $dbNiimko->selectWhere('s_specs', ['id', 'kod'], ['oopkodes' => 'gos3p']);
|
||||
|
||||
// foreach ($contingent as $key => $con) {
|
||||
// $needle = $con['spec_code'];
|
||||
// foreach ($specializations as $spec) {
|
||||
// if ($needle == $spec['kod']) {
|
||||
// $contingent[$key] += ['spec_id' => $spec['id']];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Чтобы не дублировались в базе
|
||||
// $dbOpendata->insert('sveden_education_contingent', $data);
|
||||
// $dbOpendata->update('sveden_education_contingent', $specializations);
|
||||
|
@ -27,7 +27,7 @@ class ContingentParser
|
||||
{
|
||||
libxml_use_internal_errors(true);
|
||||
$dom = new \DOMDocument();
|
||||
$dom->loadHTML($html);
|
||||
$dom->loadHTML(mb_convert_encoding($html,'HTML-ENTITIES','UTF-8'));
|
||||
$this->xpath = new \DOMXPath($dom);
|
||||
$this->template = $template;
|
||||
}
|
||||
@ -39,9 +39,9 @@ class ContingentParser
|
||||
if (!is_array($tag)) {
|
||||
$data[$field] = $this->xpath->query($this->template . $tag . "[@itemprop=\"$field\"]");
|
||||
} else {
|
||||
$x = $this->xpath->query($this->template . $tag[0] . "[@itemprop=\"$field\"]");
|
||||
$y = $this->xpath->query($this->template . $tag[1] . "[@itemprop=\"$field\"]");
|
||||
$data[$field] = $x > $y ? $x : $y;
|
||||
$th = $this->xpath->query($this->template . $tag[0] . "[@itemprop=\"$field\"]");
|
||||
$td = $this->xpath->query($this->template . $tag[1] . "[@itemprop=\"$field\"]");
|
||||
$data[$field] = $th > $td ? $th : $td;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,10 +13,10 @@ class ContingentRow
|
||||
if ($contingent < 0) {
|
||||
throw new \Exception("Недействительная численность обучающихся!");
|
||||
}
|
||||
$this->eduCode = $eduCode;
|
||||
$this->eduName = $eduName;
|
||||
$this->eduLevel = $eduLevel;
|
||||
$this->eduForm = $eduForm;
|
||||
$this->eduCode = trim($eduCode);
|
||||
$this->eduName = trim($eduName);
|
||||
$this->eduLevel = trim($eduLevel);
|
||||
$this->eduForm = trim($eduForm);
|
||||
$this->contingent = $contingent;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user