Пример #1
2
 /**
  * @todo перенести в комманды
  * Контроллер для записи Категорий
  * @Secure(roles = "ROLE_ADMIN")
  * @Route("/testxmlcat", name = "testcategories")
  */
 public function reParceCategoriesAction()
 {
     $html = file_get_contents("http://www.medknigaservis.ru/ervr/medknigaservis.xml");
     $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
     $html = iconv("windows-1251", "utf-8", $html);
     $saw = new \nokogiri($html);
     $xml = $saw->get('category')->toArray();
     #echo '<pre>';
     #print_r($xml);
     #echo '</pre>';
     #echo '<hr />';
     for ($i = 0; true; $i++) {
         if (isset($xml[$i]['#text'][0])) {
             echo '<b>' . $xml[$i]['#text'][0] . '</b><br />';
             $cat = new MarketCategory();
             $cat->setName($xml[$i]['#text'][0]);
             $cat->setOfferId($xml[$i]['id']);
             $em = $this->getDoctrine()->getManager();
             $em->persist($cat);
             $em->flush();
         } else {
             break;
         }
     }
     return $this->render('EvrikaMainBundle:Shop:main.html.twig');
 }
<?php

//Массивы для хранения конечной инфы
$date = "";
$game_id = array();
$game_title = array();
$game_time = array();
$game_pass = array();
$total_game_data = array();
$saw = new nokogiri($curl_html_data);
//ID(удобно для поиска фриролла)
$html_id = $saw->get('.comment')->toArray();
//Разбираем данные
$search_str = array("ID:", "ID: ", "(register on PokerStars via our website to enter the freeroll)");
for ($i = 0; $i < count($html_id); $i++) {
    $game_id[$i] = trim(str_replace($search_str, "", $html_id[$i]["#text"][0]));
}
//Название фрироллов
$html_title = $saw->get('.freeroll-data .game-title')->toArray();
//Разбираем данные
for ($i = 0; $i < count($html_title); $i++) {
    $game_title[$i] = $html_title[$i]["#text"][0];
}
//Пароли
$html_pass = $saw->get('.freeroll-data .passwText')->toArray();
//Разбираем данные
for ($i = 0; $i < count($html_pass); $i++) {
    $game_pass[$i] = trim(iconv("UTF-8", "ISO-8859-1", $html_pass[$i]["#text"][0]));
}
//Время проведения/Дата
$html_time = $saw->get('.getOnlyTime')->toArray();
Пример #3
0
 /**
  * Авторизация в соц сети и получение secure_token
  * позволяет миновать открытие браузера
  *
  * @param $client_id
  * @param array $scope
  * @throws AuthFailed
  */
 private function authorize($client_id, array $scope)
 {
     $response_form = $this->login_form($client_id, $scope);
     $dom = \nokogiri::fromHtml($response_form->body);
     $origin = $dom->get('input[name="_origin"]')->toArray();
     $ip_h = $dom->get('input[name="ip_h"]')->toArray();
     $lg_h = $dom->get('input[name="lg_h"]')->toArray();
     $to = $dom->get('input[name="to"]')->toArray();
     $this->session->headers['Referer'] = $response_form->url;
     $this->session->headers['Origin'] = 'https://oauth.vk.com';
     if (!$ip_h || !$lg_h || !$to || !$origin) {
         throw new AuthFailed('Wrong client id or scope');
     }
     $auth_response = $this->auth_post_request($ip_h[0]['value'], $lg_h[0]['value'], $to[0]['value'], $origin[0]['value']);
     // 405 status === OK
     if (!$auth_response->success) {
         $url = $auth_response->url;
     } else {
         $this->session->headers['Referer'] = $auth_response->url;
         $confirm_form = \nokogiri::fromHtml($auth_response->body);
         $confirm_form_data = $confirm_form->get('form[method="post"]')->toArray();
         $confirm_response = $this->post_confirm($confirm_form_data[0]['action']);
         $url = $confirm_response->url;
     }
     if (preg_match('|access_token=([^&]+)&expires_in=([^&]+)&user_id=([\\d]+)|ius', $url, $m)) {
         $this->token = array('token' => $m[1], 'expires' => $m[2] ? $m[2] + time() : 0, 'uid' => $m[3]);
         if ($this->store_path) {
             file_put_contents($this->store_path . '/token-' . md5($client_id . serialize($scope)) . '.json', json_encode($this->token));
         }
     } else {
         throw new AuthFailed('Wrong auth params!');
     }
 }
Пример #4
0
function process_bbs_appgame_url($req_url)
{
    preg_match('#^http://bbs\\.appgame\\.com/thread-[\\d]+-[\\d]+-[\\d]+\\.html$#us', $req_url, $matches);
    if ($matches == null) {
        return false;
    }
    $user_agent = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36';
    $html = curl_get_content($req_url, $user_agent);
    if (empty($html)) {
        return false;
    }
    $regex_match = "#<div id=\"post_(\\d+)\">#s";
    if (!preg_match($regex_match, $html, $match)) {
        return false;
    }
    $pid = $match[1];
    preg_match('#发表于[^<]*?<span title="([^"]*?)">.*?</span>#s', $html, $match);
    $time_str = $match[1];
    preg_match("#<title>([^<]*?)</title>#s", $html, $match);
    $title = $match[1];
    $title = preg_replace("#_[^_]+_任玩堂.*\$#u", '', $title);
    $html = mb_convert_encoding($html, 'HTML-ENTITIES', mb_detect_encoding($html));
    $saw = new nokogiri($html);
    $target = $saw->get('td#postmessage_' . $pid);
    $dom = $target->getDom();
    $node = $dom->firstChild->childNodes->item(0);
    $content = strip_tags(dom_to_html($node));
    $content = preg_replace("#[\\s]+#us", '', $content);
    preg_match('#showauthor\\(this, \'userinfo' . $pid . '\'.*?<img .*?src="([^"]+?)"#s', $html, $match);
    $user_pic = $match[1];
    $user_img = get_redirect_url($user_pic);
    $res = array();
    $res['onebox'] = 'appgame-bbs';
    $res['provider_name'] = '任玩堂论坛';
    $res['provider_url'] = 'http://bbs.appgame.com/';
    $res['favicon_url'] = 'http://www.appgame.com/favicon.ico';
    $res['ori_url'] = $req_url;
    $res['title'] = $title;
    $res['image'] = $user_img;
    $res['ID'] = intval($pid);
    $res['description'] = trim($content);
    $res['update_time'] = format_time($time_str);
    $res['create_time'] = $res['update_time'];
    return $res;
}
Пример #5
0
function __get_bbspage_form_url($ori_url, $pid, $mobile = false)
{
    $user_agent = null;
    if ($mobile) {
        $user_agent = 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3 ' . UA_ONEBOX;
    } else {
        $user_agent = 'User-Agent: ' . UA_ONEBOX;
    }
    $html = do_curl($ori_url, $user_agent);
    if (empty($html)) {
        return null;
    }
    if (empty($pid)) {
        if ($mobile) {
            $regex_match = "#<div id=\"post_(\\d+)\" class=\"vb (vc|notb)\">#s";
        } else {
            $regex_match = "#<table id=\"pid(\\d+)\" summary=\"pid(\\d+)\"#s";
        }
        if (!preg_match($regex_match, $html, $match)) {
            if (preg_match("#class=\"alert_info\".*?(<p>[^<].*?</p>)#s", $html, $match)) {
                return onebox_capsule($ori_url, 'not found', $match[1], 50);
            }
            return null;
        }
        $pid = $match[1];
    }
    if ($mobile) {
        $id_nokorigi = 'div[id=post_' . $pid . ']';
        preg_match("#<title>([^<]*?)</title>#s", $html, $match);
        $title = $match[1];
        $title = preg_replace("#_[^_]+_任玩堂#u", '', $title);
        $size = 120;
    } else {
        $id_nokorigi = 'table[id=pid' . $pid . ']';
        preg_match("#id=\"thread_subject\">([^<]*?)</a>#s", $html, $match);
        $title = $match[1];
        $size = 140;
    }
    //return "<a href=$ori_url target=\"_blank\">$title</a>";
    $html = mb_convert_encoding($html, 'HTML-ENTITIES', mb_detect_encoding($html));
    $saw = new nokogiri($html);
    $target = $saw->get($id_nokorigi);
    $dom = $target->getDom();
    remove_doc_class($dom, 'plm xg2 tip mbm cl p_pop md_ctrl pattl ad authi pi postatt box_ex2 user_first');
    $node = $dom->firstChild->childNodes->item(0);
    $content = node_to_html($node);
    $content = remove_trouble_tags($content);
    return onebox_capsule($ori_url, $title, $content, $size);
}
Пример #6
0
 /**
  * @Route("/blooo" , name="blooo" )
  */
 public function testAtmosferaAction()
 {
     #https://downloader.disk.yandex.ru/disk/49373d95452e82cf369769119e6ff2b8/52cfb5a7/t3aUbbbxRpsQHR9mmamDcCO6r8kTqbeHjLoT-qWs6_1zCvY_2tlgIKqPcgxAfA6AZAaa8cth3jpcoJR0t5IbHg%3D%3D?uid=0&filename=books%20.xml&disposition=attachment&hash=V4x4gG5Bgx9jq/YtyAidWbEe7hklvYfp8u/NvYR/jHA%3D&limit=0&content_type=text%2Fxml
     $html = file_get_contents("https://downloader.disk.yandex.ru/disk/ba8c59411011b99303d5473566ce569c/52cffe1f/t3aUbbbxRpsQHR9mmamDcCO6r8kTqbeHjLoT-qWs6_1zCvY_2tlgIKqPcgxAfA6AZAaa8cth3jpcoJR0t5IbHg%3D%3D?uid=0&filename=books%20.xml&disposition=attachment&hash=V4x4gG5Bgx9jq/YtyAidWbEe7hklvYfp8u/NvYR/jHA%3D&limit=0&content_type=text%2Fxml&fsize=76244");
     #$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
     $html = iconv("windows-1251", "utf-8", $html);
     $saw = new \nokogiri($html);
     #$date =  date('Y-m-d H:i:s', time()) ;
     $date = new \DateTime();
     $xml = $saw->get('offer')->toArray();
     //        echo '<pre>';
     //        print_r($xml);
     //        echo '</pre>';
     //        exit;
     # $mu это MarketUser
     $mu = 3;
     //        $result = $this
     //            ->getContainer()
     //            ->get('doctrine')
     //            ->getManager()
     //            ->createQuery('UPDATE EvrikaMainBundle:Market m SET m.enabled = false WHERE m.marketUser = :mu')
     //            ->setParameter('mu', $mu)
     //            ->execute();
     $result = $this->getDoctrine()->getManager()->createQuery('UPDATE EvrikaMainBundle:Market m SET m.enabled = false WHERE m.marketUser = :mu')->setParameter('mu', $mu)->execute();
     if ($result !== true) {
         #$output->writeln('ERROR : UPDATE enabled = false is Error');
     }
     $marketUser = $this->getDoctrine()->getRepository('EvrikaMainBundle:MarketUser')->findOneById(3);
     for ($i = 0; $i < 3000; $i++) {
         if (isset($xml[$i])) {
             if (isset($xml[$i]['categoryid']['0']['#text']['0'])) {
                 //                      $category = $this
                 //                            ->getContainer()
                 //                            ->get('doctrine')
                 //                            ->getManager()
                 //                            ->getRepository('EvrikaMainBundle:MarketCategory')
                 //                            ->findOneById(1);
                 $offerCategory = $xml[$i]['categoryid']['0']['#text']['0'];
                 $category = $this->getDoctrine()->getRepository('EvrikaMainBundle:MarketCategory')->findOneBy(array('offerId' => $offerCategory, 'marketUser' => $marketUser));
             } else {
                 $category = NULL;
             }
             $name = isset($xml[$i]['name']['0']['#text']['0']) ? $xml[$i]['name']['0']['#text']['0'] : '';
             $offerid = isset($xml[$i]['id']) ? $xml[$i]['id'] : '';
             $author = isset($xml[$i]['author']['0']['#text']['0']) ? $xml[$i]['author']['0']['#text']['0'] : '';
             $cena = isset($xml[$i]['price']['0']['#text']['0']) ? $xml[$i]['price']['0']['#text']['0'] : '';
             $publisher = isset($xml[$i]['publisher']['0']['#text']['0']) ? $xml[$i]['publisher']['0']['#text']['0'] : '';
             $year = isset($xml[$i]['year']['0']['#text']['0']) ? $xml[$i]['year']['0']['#text']['0'] : '';
             $isbn = isset($xml[$i]['isbn']['0']['#text']['0']) ? $xml[$i]['isbn']['0']['#text']['0'] : '';
             $page_extent = isset($xml[$i]['page_extent']['0']['#text']['0']) ? $xml[$i]['page_extent']['0']['#text']['0'] : '';
             $description = isset($xml[$i]['description']) ? $this->arrToStr($xml[$i]['description']) : '';
             #@todo Надо бы сделать человечно
             #$tableOfContents    = (isset($xml[$i]['table_of_contents']) ? $this->arrToStr($xml[$i]['table_of_contents']) : '');
             #$description = $description.' <br /> '.$tableOfContents;
             $url = isset($xml[$i]['url']['0']['#text']['0']) ? $xml[$i]['url']['0']['#text']['0'] : '';
             $currency = isset($xml[$i]['currencyid']['0']['#text']['0']) ? $xml[$i]['currencyid']['0']['#text']['0'] : '';
             $picture = isset($xml[$i]['picture']['0']['#text']['0']) ? $xml[$i]['picture']['0']['#text']['0'] : '';
             $em = $this->getDoctrine()->getManager();
             $book = $this->getDoctrine()->getManager()->getRepository('EvrikaMainBundle:Market')->findOneBy(array('offerId' => $offerid, 'marketUser' => $marketUser));
             if ($book == NULL) {
                 $action = 'INSERT';
                 $book = new Market();
                 $book->setOfferid($offerid);
                 $book->setType('book');
                 $book->setName($name);
                 $book->setCategory($category);
                 $book->setAuthor($author);
                 $book->setPublicHouse($publisher);
                 $book->setYear($year);
                 $book->setIsbn($isbn);
                 $book->setCountList($page_extent);
                 $book->setDescription($description);
                 $book->setLink($url);
                 $book->setImageURL($picture);
                 $book->setCurrency($currency);
                 $book->setCountList($page_extent);
                 $book->setCena($cena);
                 $book->setEnabled('true');
                 $book->setUpdated($date);
                 $book->setMarketUser($marketUser);
                 $em->persist($book);
             } else {
                 $action = 'UPDATE';
                 $book->setCena($cena);
                 $book->setEnabled('true');
                 $book->setUpdated($date);
             }
             $book->setEnabled(1);
             $em->flush();
             # it is debug code
             echo $action;
             echo '<br />';
             echo $book->getOfferId();
             echo '<br />';
             echo $book->getName();
             echo '<br />';
             echo $book->getAuthor();
             echo '<br />';
             echo $book->getCena();
             echo '<br />';
             echo $book->getPublicHouse();
             echo '<br />';
             echo $book->getImageURL();
             echo '<br />';
             echo $book->getCategory()->getName();
             echo '<hr />';
             #$output->writeln($offerid.' : '.$action.' ----------- OK');
         } else {
             #$output->writeln('ERROR : NOT FOUND');
         }
     }
 }
Пример #7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getArgument('type') == 'book') {
         $html = file_get_contents("http://www.medknigaservis.ru/ervr/medknigaservis.xml");
         $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
         $html = iconv("windows-1251", "utf-8", $html);
         $saw = new \nokogiri($html);
         $date = new \DateTime();
         $xml = $saw->get('offer')->toArray();
         /**
          *  Делаем поле enabled для всех книжек от этого издательства = 0
          */
         //                $mu = $this
         //                    ->getContainer()
         //                    ->get('doctrine')
         //                    ->getEntityManager()
         //                    ->getRepository('EvrikaMainBundle:marketUser')
         //                    ->findOneById(1);
         # $mu это MarketUser
         $mu = 1;
         $result = $this->getContainer()->get('doctrine')->getEntityManager()->createQuery('UPDATE EvrikaMainBundle:Market m SET m.enabled = false WHERE m.marketUser = :mu')->setParameter('mu', $mu)->execute();
         if ($result !== true) {
             $output->writeln('ERROR : UPDATE enabled = false is Error');
         }
         for ($i = 0; $i < 3500; $i++) {
             if (isset($xml[$i])) {
                 if (isset($xml[$i]['categoryid']['0']['#text']['0'])) {
                     $category = $this->getContainer()->get('doctrine')->getEntityManager()->getRepository('EvrikaMainBundle:MarketCategory')->findOneByOfferId($xml[$i]['categoryid']['0']['#text']['0']);
                 } else {
                     $category = NULL;
                 }
                 $name = isset($xml[$i]['name']['0']['#text']['0']) ? $xml[$i]['name']['0']['#text']['0'] : '';
                 $offerid = isset($xml[$i]['id']) ? $xml[$i]['id'] : '';
                 $author = isset($xml[$i]['author']['0']['#text']['0']) ? $xml[$i]['author']['0']['#text']['0'] : '';
                 $cena = isset($xml[$i]['price']['0']['#text']['0']) ? $xml[$i]['price']['0']['#text']['0'] : '';
                 $publisher = isset($xml[$i]['publisher']['0']['#text']['0']) ? $xml[$i]['publisher']['0']['#text']['0'] : '';
                 $year = isset($xml[$i]['year']['0']['#text']['0']) ? $xml[$i]['year']['0']['#text']['0'] : '';
                 $isbn = isset($xml[$i]['isbn']['0']['#text']['0']) ? $xml[$i]['isbn']['0']['#text']['0'] : '';
                 $page_extent = isset($xml[$i]['page_extent']['0']['#text']['0']) ? $xml[$i]['page_extent']['0']['#text']['0'] : '';
                 $description = isset($xml[$i]['description']) ? $this->arrToStr($xml[$i]['description']) : '';
                 $url = isset($xml[$i]['url']['0']['#text']['0']) ? $xml[$i]['url']['0']['#text']['0'] : '';
                 $currency = isset($xml[$i]['currencyid']['0']['#text']['0']) ? $xml[$i]['currencyid']['0']['#text']['0'] : '';
                 $picture = isset($xml[$i]['picture']['0']['#text']['0']) ? $xml[$i]['picture']['0']['#text']['0'] : '';
                 $marketUser = $this->getContainer()->get('doctrine')->getEntityManager()->getRepository('EvrikaMainBundle:MarketUser')->findOneByid(1);
                 $book = $this->getContainer()->get('doctrine')->getEntityManager()->getRepository('EvrikaMainBundle:Market')->findOneByOfferId($offerid);
                 $action = 'UPDATE';
                 $em = $this->getContainer()->get('doctrine')->getEntityManager();
                 if ($book == NULL) {
                     $action = 'INSERT';
                     $book = new Market();
                     $book->setOfferId($offerid);
                     $book->setType('book');
                     $book->setName($name);
                     $book->setCategory($category);
                     $book->setAuthor($author);
                     $book->setPublicHouse($publisher);
                     $book->setYear($year);
                     $book->setIsbn($isbn);
                     $book->setCountList($page_extent);
                     $book->setDescription($description);
                     $book->setLink($url);
                     $book->setImageURL($picture);
                     $book->setCurrency($currency);
                     $book->setCountList($page_extent);
                     $book->setCena($cena);
                     $book->setEnabled('true');
                     $book->setUpdated($date);
                     $book->setMarketUser($marketUser);
                     $em->persist($book);
                 } else {
                     $book->setCena($cena);
                     $book->setEnabled('true');
                     $book->setUpdated($date);
                 }
                 $book->setEnabled(1);
                 $em->flush();
                 $output->writeln($offerid . ' : ' . $action . ' ----------- OK');
             } else {
                 $output->writeln('ERROR : NOT FOUND');
             }
         }
         $result = $this->getContainer()->get('doctrine')->getEntityManager()->createQuery('DELETE FROM EvrikaMainBundle:Market m  WHERE m.enabled = false AND m.marketUser = :mu')->setParameter('mu', $mu)->execute();
         if ($result !== true) {
             $output->writeln('ERROR : DELETE  old items');
         }
     } else {
         $output->writeln('ERROR : INVALID ARGUMENT');
     }
 }
Пример #8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getArgument('type') == 'book') {
         $html = file_get_contents("https://downloader.disk.yandex.ru/disk/49373d95452e82cf369769119e6ff2b8/52cfb5a7/t3aUbbbxRpsQHR9mmamDcCO6r8kTqbeHjLoT-qWs6_1zCvY_2tlgIKqPcgxAfA6AZAaa8cth3jpcoJR0t5IbHg%3D%3D?uid=0&filename=books%20.xml&disposition=attachment&hash=V4x4gG5Bgx9jq/YtyAidWbEe7hklvYfp8u/NvYR/jHA%3D&limit=0&content_type=text%2Fxml");
         #$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
         $html = iconv("windows-1251", "utf-8", $html);
         $saw = new \nokogiri($html);
         $date = date('Y-m-d H:i:s', time());
         $xml = $saw->get('offer')->toArray();
         for ($i = 0; $i < 3000; $i++) {
             if (isset($xml[$i])) {
                 if (isset($xml[$i]['categoryid']['0']['#text']['0'])) {
                     $category = $this->getContainer()->get('doctrine')->getEntityManager()->getRepository('EvrikaMainBundle:MarketCategory')->findOneById(1);
                 } else {
                     $category = NULL;
                 }
                 $name = isset($xml[$i]['name']['0']['#text']['0']) ? $xml[$i]['name']['0']['#text']['0'] : '';
                 $offerid = isset($xml[$i]['id']) ? $xml[$i]['id'] : '';
                 $author = isset($xml[$i]['author']['0']['#text']['0']) ? $xml[$i]['author']['0']['#text']['0'] : '';
                 $cena = isset($xml[$i]['price']['0']['#text']['0']) ? $xml[$i]['price']['0']['#text']['0'] : '';
                 $publisher = isset($xml[$i]['publisher']['0']['#text']['0']) ? $xml[$i]['publisher']['0']['#text']['0'] : '';
                 $year = isset($xml[$i]['year']['0']['#text']['0']) ? $xml[$i]['year']['0']['#text']['0'] : '';
                 $isbn = isset($xml[$i]['isbn']['0']['#text']['0']) ? $xml[$i]['isbn']['0']['#text']['0'] : '';
                 $page_extent = isset($xml[$i]['page_extent']['0']['#text']['0']) ? $xml[$i]['page_extent']['0']['#text']['0'] : '';
                 $description = isset($xml[$i]['description']) ? $this->arrToStr($xml[$i]['description']) : '';
                 $url = isset($xml[$i]['url']['0']['#text']['0']) ? $xml[$i]['url']['0']['#text']['0'] : '';
                 $currency = isset($xml[$i]['currencyid']['0']['#text']['0']) ? $xml[$i]['currencyid']['0']['#text']['0'] : '';
                 $picture = isset($xml[$i]['picture']['0']['#text']['0']) ? $xml[$i]['picture']['0']['#text']['0'] : '';
                 $book = $this->getContainer()->get('doctrine')->getEntityManager()->getRepository('EvrikaMainBundle:Market')->findOneByOfferid($offerid);
                 $em = $this->getContainer()->get('doctrine')->getEntityManager();
                 if ($book == NULL) {
                     $action = 'INSERT';
                     $book = new Market();
                     $book->setOfferid($offerid);
                     $book->setType('book');
                     $book->setName($name);
                     $book->setCategory($category);
                     $book->setAuthor($author);
                     $book->setPublicHouse($publisher);
                     $book->setYear($year);
                     $book->setIsbn($isbn);
                     $book->setCountList($page_extent);
                     $book->setDescription($description);
                     $book->setLink($url);
                     $book->setImageURL($picture);
                     $book->setCurrency($currency);
                     $book->setCountList($page_extent);
                     $book->setCena($cena);
                     $book->setEnabled('true');
                     $book->setUpdated($date);
                     #$em->persist($book);
                 } else {
                     $action = 'UPDATE';
                     $book->setCena($cena);
                     $book->setEnabled('true');
                     $book->setUpdated($date);
                 }
                 $em->flush();
                 $output->writeln($offerid . ' : ' . $action . ' ----------- OK');
             } else {
                 $output->writeln('ERROR : NOT FOUND');
             }
         }
     } else {
         $output->writeln('ERROR : INVALID ARGUMENT');
     }
 }
Пример #9
0
 /**
  * Этот код для добавления больниц с сайта ros-med.info (парсер) по областям, ниже по
  * @Route("/hospital-get", name="hospital_get")
  * @Secure(roles = "ROLE_ONLY_YA")
  */
 public function getHospital()
 {
     $arrayRegion = array('1' => "Алтайский край", '168' => "Амурская область", '251' => "Архангельская область", '311' => "Астраханская область", '375' => "Брянская область", '466' => "Владимирская область", '582' => "Волгоградская область", '755' => "Воронежская область", '850' => "Забайкальский край", '946' => "Ивановская область", '1007' => "Иркутская область", '1183' => "Калининградская область", '1228' => "Калужская область", '1284' => "Камчатский край", '1324' => "Кемеровская область", '1466' => "Кировская область", '1585' => "Костромская область", '1695' => "Краснодарский край", '1923' => "Курганская область", '1976' => "Курская область", '2038' => "Ленинградская область", '2251' => "Липецкая область", '2315' => "Москва", '2855' => "Московская область", '3334' => "Мурманская область", '3398' => "Нижегородская область", '3735' => "Новгородская область", '3805' => "Новосибирская область", '3917' => "Орловская область", '3992' => "Пензенская область", '4021' => "Пермский край", '4233' => "Приморский край", '4369' => "Республика Башкортостан", '4674' => "Республика Бурятия", '4738' => "Республика Дагестан", '4973' => "Республика Карелия", '5031' => "Республика Мордовия", '5100' => "Республика Саха (Якутия)", '5177' => "Республика Татарстан", '5270' => "Ростовская область", '5463' => "Рязанская область", '5532' => "Санкт-Петербург", '5762' => "Саратовская область", '5911' => "Свердловская область", '6133' => "Смоленская область", '6191' => "Ставропольский край", '6319' => "Тамбовская область", '6373' => "Тверская область", '6496' => "Томская область", '6650' => "Тульская область", '6814' => "Удмуртская Республика", '6981' => "Ульяновская область", '7061' => "Хабаровский край", '7090' => "Чеченская республика");
     foreach ($arrayRegion as $key => $value) {
         $em = $this->getDoctrine()->getManager();
         $region = $this->getDoctrine()->getRepository('EvrikaMainBundle:Region')->findOneByTitle($value);
         /* Если такого регона нету, то добавляем, иначе обращаемся к существующему */
         if ($region == null) {
             $region = new Region();
             $region->setTitle($value);
             $em->persist($region);
             $em->flush();
             $em->refresh($region);
         }
         for ($i = 1; true; $i++) {
             $html = file_get_contents("http://www.ros-med.info/lpu/region.php?id={$key}&page={$i}&action=region-lpu");
             echo 'Сканирование ' . "<b>http://www.ros-med.info/lpu/region.php?id={$key}&page={$i}&action=region-lpu</b><br />";
             $saw = new \nokogiri($html);
             $xml = $saw->get('.main-table tr')->toArray();
             if (!isset($xml[$i])) {
                 echo 'Отказ <br /> ';
                 break;
             } else {
                 /*тут сохраняем все больнички*/
                 for ($j = 1; true; $j++) {
                     if (!isset($xml[$j]['td']['1']['#text']) && !isset($xml[$j]['td']['2']['#text'])) {
                         break;
                     }
                     /* Вначале проверяем текст на массив и если надо - сливаем в строку (особенность разбивки nokogiri)*/
                     $name = $xml[$j]['td']['1']['#text'];
                     if (is_array($name)) {
                         $name = implode('', $name);
                     }
                     $adr = $xml[$j]['td']['2']['#text'];
                     if (is_array($adr)) {
                         $adr = implode('', $adr);
                     }
                     $hospital = $this->getDoctrine()->getRepository('EvrikaMainBundle:Hospital')->findOneBy(array('region' => $region, 'title' => $name));
                     echo '<span style="padding-left: 40px;">&nbsp;</span>' . $name . ' <br />';
                     if ($hospital == null) {
                         $hospital = new Hospital();
                         $hospital->setTitle($name);
                         $hospital->setAdr($adr);
                         $hospital->setRegion($region);
                         $em->persist($hospital);
                         $em->flush();
                     }
                 }
             }
         }
     }
     exit;
 }
 private function saveIcon()
 {
     try {
         $urlData = parse_url($this->url);
         $siteUrl = $urlData['scheme'] . '://' . $urlData['host'];
         $html = (new Client())->createRequest()->setUrl($siteUrl)->send()->getContent();
         $saw = new \nokogiri($html);
         $icons = $saw->get('link[rel="icon"]')->toArray();
         $iconUrl = null;
         if ($icons) {
             $iconUrl = $icons[0]['href'];
             $iconUrl = strstr($iconUrl, 'http') === false ? $siteUrl . $iconUrl : $iconUrl;
         } else {
             $iconUrl = $siteUrl . '/favicon.ico';
         }
         $response = (new Client())->createRequest()->setUrl($iconUrl)->send();
         if ($response->isOk) {
             file_put_contents(FeedModel::getIconsPath() . '/' . $this->id . '.' . pathinfo($iconUrl, PATHINFO_EXTENSION), $response->getContent());
         }
     } catch (\Exception $e) {
     }
     return true;
 }