Skip to content

Instantly share code, notes, and snippets.

@konratnox
Created May 21, 2019 09:07
Show Gist options
  • Save konratnox/ab578aec4c155330cebf3c1d4b9327b0 to your computer and use it in GitHub Desktop.
Save konratnox/ab578aec4c155330cebf3c1d4b9327b0 to your computer and use it in GitHub Desktop.
define("BASE_URL", "http://ws3.morpher.ru/russian/declension");
function api_request($resource, $method) {
$full_url = BASE_URL . "$resource";
$options = array(
CURLOPT_URL => $full_url,
CURLOPT_HTTPHEADER => array('Content-Type: application/json',
'Accept: application/json'),
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => "NetAngels API client 0.1"
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ( $status > 399 ) {
return null;
}
return json_decode($content);
}
$res = CIBlockElement::GetList(
array('NAME' => 'ASC'),
Array(
'IBLOCK_ID' => 9
),
false,
false,
array('NAME', 'ID')
);
$i = 0;
while($ob = $res->GetNext()){
$patter = "|[a-z]|is";
$patter2 = "(област)";
if(!preg_match($patter, $ob['NAME']) && preg_match($patter2, $ob['NAME'])) {
$i++;
$phrase = urlencode($ob['NAME']);
if ($phrase) {
$apiResult = api_request("?s={$phrase}&format=json", "GET", $login, $password);
if ($apiResult) {
$arProps = array();
if ($apiResult->Р) {
$arProps['RODITELN_PADEZH'] = $apiResult->Р;
}
if ($apiResult->Д) {
$arProps['DATELNIY_PADEZH'] = $apiResult->Д;
}
if ($apiResult->В) {
$arProps['VINITELN_PADEZH'] = $apiResult->В;
}
if ($apiResult->Т) {
$arProps['TVORITELN_PADEZH'] = $apiResult->Т;
}
if ($apiResult->П) {
$arProps['PREDLOZH_PADEZH'] = $apiResult->П;
}
CIBlockElement::SetPropertyValuesEx($ob['ID'], false, $arProps);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment