90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
<?php
|
|
namespace App;
|
|
|
|
use GuzzleHttp\Exception\ClientException;
|
|
use GuzzleHttp\Exception\ConnectException;
|
|
use GuzzleHttp\Exception\RequestException;
|
|
use GuzzleHttp\Exception\ServerException;
|
|
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
|
|
use App\Library\ContingentParser;
|
|
use App\Library\Database;
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Psr7\Request;
|
|
|
|
$dbconfig = [
|
|
"host" => "10.90.1.201",
|
|
"database1" => "opendata",
|
|
"database2" => "niimko",
|
|
"user" => "niimko_user",
|
|
"password" => "MOhA17FeboXE"
|
|
];
|
|
|
|
$dbOpendata = new Database(
|
|
"mysql:host={$dbconfig['host']};dbname={$dbconfig['database1']}",
|
|
$dbconfig['user'],
|
|
$dbconfig['password']
|
|
);
|
|
|
|
$dbNiimko = new Database(
|
|
"mysql:host={$dbconfig['host']};dbname={$dbconfig['database2']}",
|
|
$dbconfig['user'],
|
|
$dbconfig['password']
|
|
);
|
|
$builder = new GenericBuilder();
|
|
$params = ['vuz', 'n', 'n'];
|
|
$query = $builder->select()
|
|
->setTable('s_vuzes')
|
|
->setColumns(['org_id' => 'kod', 'site'])
|
|
->where('AND')
|
|
->equals('ootype', 'vuz')
|
|
->equals('deleted', 'n')
|
|
->equals('fake', 'n')
|
|
->end();
|
|
$sql = $builder->write($query);
|
|
$sites = $dbNiimko->executeQuery($sql, $params);
|
|
|
|
// print_r($sites);
|
|
// $sites = [ ['site' => "http://marsu.ru"], ['site' => "http://voenmeh.ru"], ['site' => "http://angtu.ru"] ];
|
|
$i = 0;
|
|
foreach ($sites as $site) {
|
|
try {
|
|
$client = new Client();
|
|
|
|
$route = "{$site['site']}/sveden/education/";
|
|
$route = str_replace("http","https", $route);
|
|
$route = str_replace("www.","", $route);
|
|
print(++$i.". Current url: $route\n");
|
|
|
|
$response = $client->get($route);
|
|
print("StatusCode: ".$response->getStatusCode() . "\n");
|
|
|
|
$html = $response->getBody()->getContents();
|
|
$parser = new ContingentParser($html, '//tr[@itemprop="eduChislen"]//');
|
|
$contingent = $parser->getDataTable();
|
|
print_r($contingent);
|
|
} catch (ClientException $e) {
|
|
$response = $e->getCode();
|
|
} catch (RequestException $e) {
|
|
$response = $e->getCode();
|
|
} catch (ConnectException $e) {
|
|
$response = $e->getCode();
|
|
} catch (ServerException $e) {
|
|
$response = $e->getCode();
|
|
}
|
|
}
|
|
|
|
// $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);
|
|
// $data = $dbOpendata->select('sveden_education_contingent');
|