summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshat Tandon <[email protected]>2016-06-16 19:56:24 +0530
committerAkshat Tandon <[email protected]>2016-06-16 19:58:17 +0530
commit97bb13f76040433d9c69693f503f400f02469a46 (patch)
tree552ac27c900bd9410e7197f73a975c72f35dfb87
parent1e5bc6a1ffec5297b5807eb2fc463cd3dad5328b (diff)
Fix downloading of files having no content-length/file-size in their HTTP header
-rw-r--r--tools/natural-earth-vector-tiling/ne_tilegenerator.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/tools/natural-earth-vector-tiling/ne_tilegenerator.py b/tools/natural-earth-vector-tiling/ne_tilegenerator.py
index 49a00ce..4f2e5e3 100644
--- a/tools/natural-earth-vector-tiling/ne_tilegenerator.py
+++ b/tools/natural-earth-vector-tiling/ne_tilegenerator.py
@@ -55,8 +55,11 @@ def download(filename, in_dir):
r = http.request('GET', url, preload_content=False)
chunk_size = 8192
file_size_dl = 0
- fileSize = int(r.getheader("content-length"))
-
+ content_length = r.getheader("content-length")
+ if content_length != None:
+ fileSize = int(r.getheader("content-length"))
+ else:
+ fileSize = None
with open(os.path.join(in_dir, filename + '.zip'), 'wb') as out:
while True:
data = r.read(chunk_size)
@@ -64,7 +67,10 @@ def download(filename, in_dir):
break
file_size_dl += len(data)
out.write(data)
- print ("Downloading %s: %.1f/%.1f Mb (%3.1f%%)\r" % (filename, file_size_dl / 1024.0 / 1024.0, fileSize / 1024.0 / 1024.0, file_size_dl * 100. / fileSize), end='')
+ if fileSize != None:
+ print ("Downloading %s: %.4f/%.4f Mb (%3.1f%%)\r" % (filename, file_size_dl / 1024.0 / 1024.0, fileSize / 1024.0 / 1024.0, file_size_dl * 100. / fileSize), end='')
+ else:
+ print ("Downloading %s: %.4f Mb downloaded (file size unknown)\r" % (filename, file_size_dl / 1024.0 / 1024.0), end='')
r.release_conn()
out.close()
print ("Done")
@@ -72,7 +78,6 @@ def download(filename, in_dir):
def parse_file(filename, in_dir):
level_info = {}
path = os.path.join(in_dir, filename)
- print('ak Path', path)
f = open(path, 'rU')
for line in f:
line = line.rstrip()