diff --git a/zonedata-download/download.py b/zonedata-download/download.py index b91a226..6b25289 100755 --- a/zonedata-download/download.py +++ b/zonedata-download/download.py @@ -6,6 +6,7 @@ import sys from urlparse import urlparse import os +import cgi # Create a session s = requests.Session() @@ -48,12 +49,15 @@ for url in urls: r = s.get(config['base_url'] + url) if r.status_code == 200: - parsed_url = urlparse(r.url) - filename = os.path.basename(parsed_url.path) + _, c = cgi.parse_header(r.headers['content-disposition']) + filename = c['filename'] + if filename == "": + parsed_url = urlparse(r.url) + filename = os.path.basename(parsed_url.path) + '.txt.gz' directory = './zonefiles' if not os.path.exists(directory): os.makedirs(directory) - path = directory + '/' + filename + '.txt.gz' + path = directory + '/' + filename with open(path, 'wb') as f: for chunk in r.iter_content(1024): f.write(chunk)