def download_api_data(filename, coord, api_base, projection):
 (s, host, path, p, q, f) = urlparse(api_base)
 bbox = coordinate_latlon_bbox(coord, projection)
 path = join(path, ('api/0.6/map?bbox=%.6f,%.6f,%.6f,%.6f' % bbox))
 conn = HTTPConnection(host)
 conn.request('GET', path, headers={'Accept-Encoding': 'compress, gzip'})
 resp = conn.getresponse()
 assert (resp.status == 200), (resp.status, resp.read())
 if (resp.getheader('Content-Encoding') == 'gzip'):
  disk = open(filename, 'w')
 else:
  raise Exception((host, path))
  disk = GzipFile(filename, 'w')
 bytes = resp.read()
 disk.write(bytes)
 disk.close()
 return (len(bytes) / 1024.0)

def download_api_data ( filename , coord , api_base , projection ) : ( s , host , path , p , q , f ) = urlparse ( api_base ) bbox = coordinate_latlon_bbox ( coord , projection ) path = join ( path , ( 'api/0.6/map?bbox=%.6f,%.6f,%.6f,%.6f' % bbox ) ) conn = HTTPConnection ( host ) conn . request ( 'GET' , path , headers = { 'Accept-Encoding' : 'compress, gzip' } ) resp = conn . getresponse ( ) assert ( resp . status == 200 ) , ( resp . status , resp . read ( ) ) if ( resp . getheader ( 'Content-Encoding' ) == 'gzip' ) : disk = open ( filename , 'w' ) else : raise Exception ( ( host , path ) ) disk = GzipFile ( filename , 'w' ) bytes = resp . read ( ) disk . write ( bytes ) disk . close ( ) return ( len ( bytes ) / 1024.0 )
download api data for a tile to a named file .