Example #1
0
 public function run($args)
 {
     $link = "http://olx.uz";
     $listPages = array();
     $newCache = CatalogCache::fetchBySlug("torg_uz");
     if (!$newCache->description) {
         $newCache1 = CatalogCache::fetchBySlug("torg_uz_page");
         if ($newCache1->description == 1) {
             $text = file_get_contents("http://www.olx.uz/ru/all");
         } else {
             $text = file_get_contents("http://www.olx.uz/ru/all/page/" . $newCache1->description);
         }
         $arr = explode("offers blue offers", $text);
         //echo $arr[0]."###";
         //echo $arr[1];
         //die;
         if (empty($arr[1])) {
             echo "Oy";
             echo $arr[0];
             die;
         }
         $arr = explode("/ru/changeview", $arr[1]);
         $arr = explode("</tr>", $arr[0]);
         for ($i = 1; $i < sizeof($arr) - 1; $i++) {
             $arr1 = explode('href="', $arr[$i]);
             $arr1 = explode('"', $arr1[1]);
             $listPages[] = trim($link . $arr1[0]);
         }
         $newCache->description = serialize($listPages);
         $newCache->date = time();
         if (!$newCache->save()) {
             print_r($newCache->getErrors());
         }
     } else {
         $listPages = unserialize($newCache->description);
     }
     $countPage = 0;
     for ($i = 0; $i < sizeof($listPages); $i++) {
         $checkModel = CatalogUpload::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("name='" . $listPages[$i] . "'")->setCache(0));
         if (sizeof($checkModel) == 0) {
             $countPage++;
             $text = file_get_contents($listPages[$i]);
             if (strpos($text, "mailto") !== false) {
                 $arr = explode("Имя:", $text);
                 $arr = explode("</table>", $arr[1]);
                 $arrE = explode("mailto:", $arr[0]);
                 $arrE = explode('"', $arrE[1]);
                 $email = trim($arrE[0]);
                 $arrN = explode("</tr>", $arr[0]);
                 $arrN = explode("<td", $arrN[0]);
                 $name = strip_tags("<p" . $arrN[1]);
                 echo "##" . $email . "-" . $name;
                 //.;
                 $chechEmail = CatalogUsersSubscribe::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("email='" . $email . "'")->setCache(0));
                 if (sizeof($chechEmail) == 0) {
                     echo "N0";
                     //.;
                     $newSubscribe = new CatalogUsersSubscribe();
                     $newSubscribe->name = trim($name);
                     $newSubscribe->email = trim($email);
                     if (!$newSubscribe->save()) {
                         print_r($newSubscribe->getErrors());
                     }
                 }
                 //break;
             }
             $newPage = new CatalogUpload();
             $newPage->name = $listPages[$i];
             if (!$newPage->save()) {
                 print_r($newPage->getErrors());
             }
         }
     }
     // Если не нашол не одной новой стринцы то скидываем кеш, и устанавливаем текущей следующую страницу
     if ($countPage == 0) {
         $newCache = CatalogCache::fetchBySlug("torg_uz");
         $newCache->description = "";
         $newCache->save();
         $newCache1 = CatalogCache::fetchBySlug("torg_uz_page");
         $newCache1->description = (int) $newCache1->description + 1;
         $newCache1->save();
     }
 }
 public function run($args)
 {
     $link = "http://boplus.uz";
     $listPages = array();
     $cacheTopCategory = CatalogCache::fetchBySlug("boplus_uz_top_category");
     if ($cacheTopCategory->date == 0 || $cacheTopCategory->date <= time()) {
         $text = file_get_contents($link);
         $arr = explode('class="catalog"', $text);
         $arr = explode('id="yandex_ad"', $arr[1]);
         $arr = explode('class="subcategory_name""', $arr[0]);
         $listTopCategory = array();
         for ($i = 1; $i < sizeof($arr); $i++) {
             $arr2 = explode('href="', $arr[$i]);
             $arr2 = explode('"', $arr2[1]);
             $listTopCategory[] = $link . $arr2[0];
         }
         $cacheTopCategory->description = serialize($listTopCategory);
         $cacheTopCategory->date = time() + 60 * 60 * 24 * 7 * 4;
         $cacheTopCategory->save();
     } else {
         $listTopCategory = unserialize($cacheTopCategory->description);
     }
     // Начинаем ходить по категориям и выстаскивать объявления
     $cacheCategory = CatalogCache::fetchBySlug("yp_uz_current_category");
     if ($cacheCategory->description) {
         $currentCategory = $listSubCategory[$cacheCategory->description];
     } else {
         // Сохраняем текщую категорию
         $currentCategory = $listSubCategory[0];
         $cacheCategory->description = 0;
         $cacheCategory->date = time();
         $cacheCategory->save();
     }
     // Определяем текущую страницу данной категории
     $page = CatalogCache::fetchBySlug("yp_uz_page");
     if ($page->description > 0) {
         $currentPage = $page->description;
     }
     for ($n = 0; $n < 30; $n++) {
         if ($currentPage == 1) {
             $loadPage = $currentCategory;
         } else {
             $loadPage = $currentCategory . "?page=" . $currentPage . "&pagesize=10";
         }
         echo $loadPage . "<br/>";
         $text = file_get_contents($loadPage);
         $arr = explode('id="ov"', $text);
         $arr = explode('class="header2">', $arr[1]);
         echo sizeof($arr) . "*";
         // Значит кончались страницы в этой категории
         if (sizeof($arr) == 1) {
             // Скидываем страницу до первой
             $page = CatalogCache::fetchBySlug("yp_uz_page");
             $page->description = 1;
             $page->date = time();
             $page->save();
             // Сохраняем новую категорию
             $currentCategory = CatalogCache::fetchBySlug("yp_uz_current_category");
             $currentCategory->description = $currentCategory->description + 1;
             $currentCategory->save();
             // Выходим из цикла
             break;
         }
         for ($i = 1; $i < sizeof($arr); $i++) {
             if (strpos($arr[$i], "Email") !== false) {
                 $arr2 = explode('</a>', $arr[$i]);
                 $name = trim(strip_tags($arr2[0]));
                 $arr2 = explode('mailto:', $arr2[1]);
                 $arr2 = explode('"', $arr2[1]);
                 $check = CatalogUsersSubscribe::findByAttributes(array("email" => $arr2[0]));
                 if (sizeof($check) == 0) {
                     $user = new CatalogUsersSubscribe();
                     $user->name = $name;
                     $user->email = $arr2[0];
                     $user->save();
                 }
             }
         }
         // Сохраняем текущую страницу
         $currentPage++;
         $page->description = $currentPage;
         $page->date = time();
         $page->save();
     }
 }
 public function run($args)
 {
     echo "*";
     $link = "http://proavto.uz";
     $listPages = array();
     $newCache = CatalogCache::fetchBySlug("proavto.uz");
     if (!$newCache->description) {
         echo "*";
         $newCache1 = CatalogCache::fetchBySlug("proavto_uz_page");
         if ($newCache1->description == 1) {
             $text = file_get_contents("http://proavto.uz/ru/ads/search?sortby=datenew&pageSize=10");
         } else {
             $text = file_get_contents("http://proavto.uz/ru/ads/search?sortby=datenew&pageSize=10&page=" . $newCache1->description);
         }
         $arr = explode('class="foot"', $text);
         $arr = explode('class="adcell"', $arr[0]);
         for ($i = 1; $i < sizeof($arr) - 1; $i++) {
             $arr1 = explode('class="add_wish', $arr[$i]);
             $arr1 = explode('href="', $arr1[0]);
             $arr1 = explode('"', $arr1[1]);
             $listPages[] = trim($link . $arr1[0]);
         }
         $newCache->description = serialize($listPages);
         $newCache->date = time();
         if (!$newCache->save()) {
             print_r($newCache->getErrors());
         }
         print_r($listPages);
     } else {
         $listPages = unserialize($newCache->description);
     }
     die("&");
     $countPage = 0;
     for ($i = 0; $i < sizeof($listPages); $i++) {
         $checkModel = CatalogUpload::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("name='" . $listPages[$i] . "'")->setCache(0));
         if (sizeof($checkModel) == 0) {
             $countPage++;
             $text = file_get_contents($listPages[$i]);
             if (strpos($text, "mailto") !== false) {
                 $arrE = explode("mailto:", $text);
                 $arrE = explode('"', $arrE[1]);
                 $email = trim($arrE[0]);
                 $arrE = explode("@", $email);
                 $name = $arrE[0];
                 echo "##" . $email . "-" . $name;
                 //.;
                 $chechEmail = CatalogUsersSubscribe::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("email='" . $email . "'")->setCache(0));
                 if (sizeof($chechEmail) == 0) {
                     $newSubscribe = new CatalogUsersSubscribe();
                     $newSubscribe->name = trim($name);
                     $newSubscribe->email = trim($email);
                     if (!$newSubscribe->save()) {
                         print_r($newSubscribe->getErrors());
                     }
                 }
                 //break;
             }
             $newPage = new CatalogUpload();
             $newPage->name = $listPages[$i];
             $newPage->site = "proavto.uz";
             if (!$newPage->save()) {
                 print_r($newPage->getErrors());
             }
         }
     }
     // Если не нашол не одной новой стринцы то скидываем кеш, и устанавливаем текущей следующую страницу
     if ($countPage == 0) {
         $newCache = CatalogCache::fetchBySlug("proavto.uz");
         $newCache->description = "";
         $newCache->date = 0;
         $newCache->save();
         $newCache1 = CatalogCache::fetchBySlug("proavto_uz_page");
         $newCache1->description = (int) $newCache1->description > 0 ? (int) $newCache1->description + 1 : ($newCache1->description = 2);
         $newCache1->date = 0;
         if (!$newCache1->save()) {
             $newCache1->getErrors();
         }
     }
 }