Заменены названия городов на правильные
Добавлено сообщение о неправильном или поврежденном архиве.
Скрипт для обновления 2GIS
20.10.2013 15:12
0В массиве $cities находятся именования городов, которые необходимо скачать.
Посмотреть как какой город обзывается можно, либо попробовав вручную скачать город с сайта 2gis (название фалйа), либо же в папке с установленной программой.
Сам скрипт:
$dst = dirname( __FILE__ ); define( "TIMEOUT", 300 ); $cities = array( "ekaterinburg", "chelyabinsk", "moscow", "nizhniy-tagil", "perm", "sankt-peterburg", "tyumen" ); $sel = strtolower( @$argv[1] ); if ( $sel ) { foreach( $cities as $city ) { if ( $city == $sel ) { $cities = array( $city ); break; } } if ( count( $cities ) > 1 ) die( "Can't find city \"{$sel}\"..." ); } foreach( $cities as $city ) { $last_len = 0; echo "Download {$city} map... "; $fname = "Data_" . ucfirst( $city ); $zipFile = "{$dst}/mapsZip/{$fname}.zip"; $dgdatFile = "Data_{$fname}.dgdat"; $fp = fopen( $zipFile, "w" ); $url = "http://info.2gis.ru/distributive/{$city}/last/linux/"; $ch = curl_init(); curl_setopt( $ch, CURLOPT_BINARYTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 ); curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 ); curl_setopt( $ch, CURLOPT_COOKIEJAR, "cookies.txt" ); //initiates cookie file if needed curl_setopt( $ch, CURLOPT_COOKIEFILE, "cookies.txt" ); // Uses cookies from previous session if exist curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, TIMEOUT ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT_MS, TIMEOUT * 1000 ); curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT ); curl_setopt( $ch, CURLOPT_TIMEOUT_MS, TIMEOUT * 1000 ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); curl_setopt( $ch, CURLOPT_SSLVERSION, 3 ); curl_setopt( $ch, CURLOPT_AUTOREFERER, 1 ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: ru,en-us;q=0.7,en;q=0.3', 'User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)' ) ); curl_setopt( $ch, CURLOPT_FILE, $fp ); curl_setopt( $ch, CURLOPT_PROGRESSFUNCTION, "progress" ); curl_setopt( $ch, CURLOPT_NOPROGRESS, false ); curl_setopt( $ch, CURLOPT_POST, 0 ); curl_setopt( $ch, CURLOPT_REFERER, $url ); curl_setopt( $ch, CURLOPT_URL, $url ); $data = curl_exec( $ch ); $ce = curl_error( $ch ); curl_close( $ch ); fclose( $fp ); if ( $ce ) { echo( "CURL return error: {$ce}\n" ); continue; } echo "\n"; if ( file_exists( $zipFile ) ) { $zip = new ZipArchive(); if ( $zip->open( $zipFile ) === true ) { for ( $i = 0; $i < $zip->numFiles; $i++ ) { $name = $zip->getNameIndex( $i ); if ( pathinfo( $name, PATHINFO_EXTENSION ) == "dgdat" ) { copy( "zip://{$zipFile}#{$name}", "{$dst}/maps/" . basename( $name ) ); echo( "{$city}.dgdat created...\n" ); break; } } $zip->close(); } else echo( "zip file corrupted, probably uncompleted or not found...\n" ); } echo( "\n\n" ); } function progress( $download_size, $downloaded, $upload_size, $uploaded ) { global $last_len; if ( $download_size > 0 ) { echo( str_repeat( Chr(8), $last_len ) ); $str = number_format( ( $downloaded / $download_size * 100 ), 1 ). "%"; $last_len = strlen( $str ); echo $str; } @ob_flush(); flush(); }
20.10.2013, Protocoder