public function index($token) { if ($token === 'W2Xcoiq28sLNasiszA819qgLk42CTc5b') { $addressees = Model::all(); $news = News::getForDelivery(); $tenders = Tender::getForDelivery(); $vacancies = Vacancy::getForDelivery(); $shares = Share::getForDelivery(); $expert_advices = ExpertAdvice::getForDelivery(); foreach ($addressees as $addressee) { $params['title'] = $addressee->locale . '_title'; $params['text'] = $addressee->locale . '_text'; $params['locale'] = $addressee->locale; $addressee->news && count($news) ? $params['delivery']['news'] = $news : null; $addressee->tenders && count($tenders) ? $params['delivery']['tenders'] = $tenders : null; $addressee->vacancies && count($vacancies) ? $params['delivery']['vacancies'] = $vacancies : null; $addressee->shares && count($shares) ? $params['delivery']['shares'] = $shares : null; $addressee->expert_advices && count($expert_advices) ? $params['delivery']['expert_advices'] = $expert_advices : null; if (isset($params['delivery'])) { Mail::send('emails.delivery', $params, function ($message) use($addressee) { $from_address = MailConfig::first(); $from_name = Config::get('mail.from'); $message->from($from_address->feedback_mail, $from_name['name']); $message->to($addressee->email)->subject(trans('front-end' . DS . 'emails' . DS . 'delivery.subject')); }); } unset($params); } News::where('sended', 0)->update(['sended' => 1]); Tender::where('sended', 0)->update(['sended' => 1]); Vacancy::where('sended', 0)->update(['sended' => 1]); Share::where('sended', 0)->update(['sended' => 1]); ExpertAdvice::where('sended', 0)->update(['sended' => 1]); } }
public function nokogiriParseAndSave($html, $hhId, $link = null) { if (!$html) { return 'Parse error'; } $vacancy = new Vacancy(); if ($vacancy->where('hh_id', '=', $hhId)->first()) { return 'Vacancy ' . $hhId . ' found in database'; } $saw = new nokogiri($html); $sv['title'] = $saw->get('h1.b-vacancy-title')->toText(); $sv['descr'] = $saw->get('.b-vacancy-desc-wrapper')->toTextArray(); $sv['addr'] = $saw->get('.vacancy-address-text')->toText(); $sv['company'] = $saw->get('.companyname')->toText(); dd($sv); /* $vacancy = new Vacancy; $vacancy->name = $title; // save if (!$vacancy->save()) { return 'Vacancy not saved'; } */ return true; }
public function show($id) { $infoConfig = InfoConfig::first()->toArray(); $object = Model::find($id); if (!$object) { $object = Model::where('alias', $id)->first(); } if ($object) { return view('info.vacancy', ['object' => $object, 'type' => 'vacancies', 'title' => LANG . '_title', 'description' => LANG . '_description', 'text' => LANG . '_text', 'requirements' => LANG . '_requirements', 'contacts' => LANG . '_contacts', 'infoConfig' => $infoConfig]); } return redirect('info-center'); }
public function parseAndSave($html, $hhId, $link = null) { if (!$html) { return 'Parse error'; } $vacancy = new Vacancy(); if ($vacancy->where('hh_id', '=', $hhId)->first()) { return 'Vacancy ' . $hhId . ' found in database'; } //name if ($obj = $html->find('.b-vacancy-title', 0)) { $title = $obj->plaintext; } //description if ($obj = $html->find('.b-vacancy-desc-wrapper', 0)) { $description = $obj->innertext; } //address if ($obj = $html->find('.vacancy-address-text', 0)) { $address = $obj->innertext; } //company_name if ($obj = $html->find('.companyname', 0)) { $companyName = $obj->plaintext; } //employmentMode $employmentMode = array(); foreach ($html->find('.b-vacancy-employmentmode span') as $span) { $employmentMode[] = $span->innertext; } $head = $html->find('.b-vacancy-info .l-content-3colums', 0)->innertext; if ($res = $html->str_get_html($head)) { //content if ($obj = $res->find('.l-content-colum-1', 1)) { if ($tag = $obj->find('.l-paddings meta', 0)) { $currency = $tag->content; } } //salary if ($obj = $res->find('.l-content-colum-1', 1)) { if ($tag = $obj->find('.l-paddings', 0)) { $salaryText = $tag->plaintext; } } if (!empty($salaryText)) { if (!preg_match('/[\\d]{1}/i', $salaryText)) { $salary_from = 0; $salary_to = 0; } else { $salary = explode('до', $salaryText); if (isset($salary[0]) && strlen(trim($salary[0])) > 0) { preg_match_all('/[\\w]{2}(.*)[\\w\\s\\.]{1,4}/', $salary[0], $matches); $str = str_replace(chr(194) . chr(160), '', $matches[0][0]); $str = str_replace(' ', '', $str); $salary_from = intval($str); } if (isset($salary[1]) && strlen(trim($salary[1])) > 0) { preg_match_all('/[\\w\\s]{1,2}(.*)[\\w\\s]{1,3}/', $salary[1], $matches); $str = str_replace(chr(194) . chr(160), '', $matches[0][0]); $str = str_replace(' ', '', $str); $salary_to = intval($str); } } } //cityName if ($obj = $res->find('.l-content-colum-2', 1)) { if ($tag = $obj->find('.l-paddings', 0)) { $cityName = $tag->plaintext; } } //metro if ($obj = $res->find('.l-content-colum-2', 1)) { if ($tag = $obj->find('.metro-station', 0)) { $metro = $tag->plaintext; } } if (isset($metro)) { $cityName = str_replace(',', '', $cityName); $cityName = str_replace(',', '', $metro); $cityName = trim($cityName); } //experience if ($obj = $res->find('.l-content-colum-3', 1)) { if ($tag = $obj->find('.l-paddings', 0)) { $experience = $tag->plaintext; } } } // Save Vacancy $vacancy = new Vacancy(); if (isset($title)) { $vacancy->name = $title; } if (isset($companyName)) { $vacancy->company_name = $companyName; } if (isset($hhId)) { $vacancy->hh_id = $hhId; } if (isset($link)) { $vacancy->hh_link = $link; } if (isset($salary_from)) { $vacancy->salary_from = $salary_from; } if (isset($salary_to)) { $vacancy->salary_to = $salary_to; } if (isset($currency)) { $vacancy->currency = $currency; } if (isset($cityName)) { $cities = new City(); if ($city = $cities->where('name', '=', $cityName)->first()) { $vacancy->city_id = $city->id; } else { // save new city $city = new City(); $city->name = $cityName; $city->save(); $vacancy->city_id = $city->id; } } if (isset($experience)) { $vacancy->experience = $experience; } if (isset($description)) { $vacancy->description = $description; } if (isset($address)) { $vacancy->address = $address; } // save if (!$vacancy->save()) { return 'Vacancy not saved'; } // Employment Types Save if (count($employmentMode) > 0) { $empType = new \App\EmploymentType(); foreach ($employmentMode as $emp) { if ($find = $empType->where('name', 'LIKE', '%' . $emp . '%')->first()) { $empIds[] = $find->id; } else { // save new EmploymentType $employ = new EmploymentType(); $employ->name = $emp; $employ->save(); $empIds[] = $employ->id; } } $empType = new \App\EmploymentType(); $vacancy->employmentTypes()->attach($empIds); } return true; }
protected function parseNext() { //Получаем последний hh id из базы и увеличиваем на 1 //если база пустая берем значение по умолчанию $vacancy = new Vacancy(); $lastId = $vacancy->maxId(); if ($lastId) { $lastVacancy = $vacancy->find($lastId); $hhId = $lastVacancy->hh_id; } if (isset($hhId)) { $hhId = intval($hhId) + 1; $link = $this->link_tpl . $hhId; } else { $hhId = $this->default_hh_id; $link = $this->link_tpl . $hhId; } // Simple HTML Dom //Ищем страницу вакансии //если есть в базе вычисляем новый Id //Получение страниц ведется сначала в большую сторону //если превышен лимит, меняем направление $index = 0; $maxLoadIndex = 10; $operand = '+'; $html = $vacancy->getHtmlDom($link); while (!$html) { if ($operand == '+') { $hhId = intval($hhId) + 1; } else { $hhId = intval($hhId) - 1; } if ($vacancy->where('hh_id', '=', $hhId)->first()) { continue; } if ($index++ > $maxLoadIndex) { $operand = '-'; $maxLoadIndex = 100; $index = 0; $hhId = $vacancy->minId(); } $link = $this->link_tpl . $hhId; $html = $vacancy->getHtmlDom($link); } // парсинг полученной страницы вакансии // и запись в базу $ret = $vacancy->parseAndSave($html, $hhId, $link); if ($ret === true) { return $link; } else { return $ret; } }