public function sos() { ini_set('memory_limit', '1024M'); $cache = Caching::instance('crawl.sos'); require_once APPLICATION_PATH . DS . '..' . '/public/vendeur/lib/simple_html_dom.php'; set_time_limit(0); $regions = $cache->get('regions', []); if (empty($regions)) { $html = $cache->get('html.regions'); if (empty($html)) { $html = dwn('http://www.starofservice.com/annuaire'); $cache->set('html.regions', $html); } $html = str_get_html($html); $div = $html->find('.region', 0); $div = $div->find('.standard-container', 0); $ul = $div->find('ul', 0); $lis = $ul->find('li'); foreach ($lis as $li) { $a = $li->find('a', 0); $href = $a->attr['href']; $regions[] = Arrays::last(explode('/', $href)); } $cache->set('regions', $regions); } $departments = $cache->get('departments', []); if (empty($departments)) { foreach ($regions as $region) { $html = $cache->get('html.region.' . $region); if (empty($html)) { $html = dwn("http://www.starofservice.com/annuaire/region/{$region}"); $cache->set('html.region.' . $region, $html); } $html = str_get_html($html); $div = $html->find('.region', 0); $div = $div->find('.standard-container', 0); $ul = $div->find('ul', 0); $lis = $ul->find('li'); foreach ($lis as $li) { $a = $li->find('a', 0); $href = $a->attr['href']; $tab = explode('/' . $region . '/', $href); $department = $region . '/' . $tab[1]; $departments[] = $department; } } $cache->set('departments', $departments); } $count = 0; // foreach ($departments as $department) { // $cache = redis(); // $html = $cache->get('html.department.' . str_replace('/', '.', $department)); // list($r, $d) = explode('/', $department, 2); // if (empty($html)) { // $html = dwn("http://www.starofservice.com/annuaire/departement/$department"); // $cache->set('html.department.' . str_replace('/', '.', $department), $html); // } // } // dd('termine'); foreach ($departments as $department) { $cache = redis(); $html = $cache->get('html.department.' . str_replace('/', '.', $department)); list($r, $d) = explode('/', $department, 2); if (empty($html)) { $html = dwn("http://www.starofservice.com/annuaire/departement/{$department}"); $cache->set('html.department.' . str_replace('/', '.', $department), $html); } $html = Utils::cut('<div class="region">', '</div>', $html); $ul = Utils::cut('<ul>', '</ul>', $html); $lis = explode('<li>', $ul); array_shift($lis); foreach ($lis as $li) { $li = trim(str_replace(["\t", "\n", "\r"], "", $li)); $a = Utils::cut('<a ', '/a>', $li); $href = Utils::cut('href="', '"', $a); $tab = explode('/', $href); array_shift($tab); array_shift($tab); $row = []; $row['name'] = end($tab); $row['href'] = $href; $row['region'] = $r; $row['department'] = $d; $row['category'] = $tab[0]; $sos_id = $row['sosid'] = (int) $tab[2]; $where = $tab[1]; $row['zip'] = null; if (fnmatch('*-*', $where)) { $tabWhere = explode('-', $where); $row['zip'] = (int) array_shift($tabWhere); $row['city'] = implode(" ", $tabWhere); if (is_numeric($row['city'])) { $row['zip'] = (int) $row['city']; $row['city'] = null; } } else { $row['city'] = $where; } $row['rs'] = str_replace('-', ' ', end($tab)); // $exists = $cache->get('company.' . $sos_id); // if (!$exists) { rdb('data', 'sos')->create($row)->insert(); $count++; echo "{$count} => {$r}, {$d} [" . current($tab) . "] {$sos_id} " . end($tab) . "\n"; // $cache->set('company.' . $sos_id, $service->id); // } } } }
public function __construct() { $this->db = C::instance('front.db'); }
public function getAddressByCoords($lat, $lng, $city = false) { $infos = []; $lat = str_replace(',', '.', $lat); $lng = str_replace(',', '.', $lng); $cache = \Dbredis\Caching::instance('geo'); $urlLocalisation = "http://uws2.mappy.net/data/map/1.0/loc/get.aspx?opt.format=json&opt.interactive=1&opt.language=fre&opt.xmlOutput=3v0&opt.favoriteCountry=250&x={$lng}&y={$lat}"; $key = 'lat.long.address.' . $lat . '.' . $lng; $json = redis()->get($key); if (!$json) { $json = dwn($urlLocalisation); redis()->set($key, $json); } $tab = json_decode($json, true); $data = isAke(isAke($tab, 'kml', []), 'Document', []); $placemark = isAke($data, 'Placemark', []); if (!empty($placemark)) { $AddressDetails = isAke($placemark, 'AddressDetails', []); $Country = isAke($AddressDetails, 'Country', []); $AdministrativeArea = isAke($Country, 'AdministrativeArea', []); $AdministrativeAreaName = isAke($AdministrativeArea, 'AdministrativeAreaName', ''); $Locality = isAke($AdministrativeArea, 'Locality', []); $LocalityName = isAke($Locality, 'LocalityName', ''); $Thoroughfare = isAke($Locality, 'Thoroughfare', []); $postalCode = isAke($Thoroughfare, 'PostalCode', []); $street = isAke($Thoroughfare, 'ThoroughfareName', ''); $PostalCodeNumber = isAke($postalCode, 'PostalCodeNumber', ''); $ExtendedData = isAke($placemark, 'ExtendedData', []); $address = isAke($placemark, 'name'); if (!empty($ExtendedData)) { $mappy_address_lines = isAke($ExtendedData, 'mappy:address_lines', []); if (!empty($mappy_address_lines)) { $mappy_line = isAke($mappy_address_lines, 'mappy:line', []); if (!empty($mappy_line)) { $address = current($mappy_line); } } } $department = ''; if (strlen($PostalCodeNumber)) { $department = substr($PostalCodeNumber, 0, 2); } return !$city ? isAke($placemark, 'name') : ['address' => $address, 'street' => $street, 'city' => $LocalityName, 'zip' => $PostalCodeNumber, 'department' => $department, 'region' => $AdministrativeAreaName, 'country' => isAke($Country, 'CountryName', 'France')]; } else { return false; } }
function dbCache($ns = null) { $ns = is_null($ns) ? 'db.cache' : 'db.' . $ns; return Caching::instance($ns); }