Skip to content

Instantly share code, notes, and snippets.

@varnav
Last active December 22, 2016 16:07
Show Gist options
  • Save varnav/196162fada4b84873d5a to your computer and use it in GitHub Desktop.
Save varnav/196162fada4b84873d5a to your computer and use it in GitHub Desktop.
Get amount of jobs with given salaries from hh.ru
#!/usr/bin/php
<?php
// Get amount of jobs with given salaries from hh.ru
// Add this to /etc/cron for every 2 hours check and record:
// 00 */2 * * * user /home/user/queryhhjobs.php >> /home/user/jobs.csv
// or use user-level crontab with "crontab -e"
function getjobcount($salary_from = -1)
{
$uagent = 'Counter 0.2 (https://gist.github.com/varnav/196162fada4b84873d5a)';
$position = rawurlencode('Системный администратор'); // Поменяйте на то, что вам по душе
if ($salary_from < 0) {
// Задана Москва. Кто не из Москвы - проставьте свою area, список здесь: https://api.hh.ru/areas
$url = "https://api.hh.ru/vacancies?search_field=name&text=$position&area=1&per_page=0"; // Все
} else
$url = "https://api.hh.ru/vacancies?search_field=name&text=$position&area=1&per_page=0&salary=$salary_from&only_with_salary=true"; // Только с указанием зарплат от
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // не проверять сертификат. небезопасно? и пофиг.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // возвращает веб-страницу
curl_setopt($ch, CURLOPT_HEADER, 0); // не возвращает заголовки
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // переходит по редиректам
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); // останавливаться после 10-ого редиректа
$content = curl_exec($ch);
$result = json_decode($content, true);
return $result['found'];
}
echo date("Y-m-d H:i:s") . ',' . getjobcount() . ',' . getjobcount(25000) . ',' . getjobcount(50000) . ',' . getjobcount(75000) . ',' . getjobcount(100000) . ',' . getjobcount(125000) . PHP_EOL;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment