Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace cgi module (deprecated) #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions download.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import json
import sys
import cgi
import os
import datetime

from email.message import Message
from do_authentication import authenticate
from do_http_get import do_get

Expand Down Expand Up @@ -97,6 +96,11 @@ def get_zone_links(czds_base_url):
# Fourth Step: download zone files
##############################################################################################################

def _parse_header(header):
m = Message()
m['content-type'] = header
return m

# Function definition to download one zone file
def download_one_zone(url, output_directory):
print("{0}: Downloading zone file from {1}".format(str(datetime.datetime.now()), url))
Expand All @@ -108,8 +112,8 @@ def download_one_zone(url, output_directory):

if status_code == 200:
# Try to get the filename from the header
_,option = cgi.parse_header(download_zone_response.headers['content-disposition'])
filename = option.get('filename')
option = _parse_header(download_zone_response.headers['content-disposition'])
filename = option.get_param('filename')

# If could get a filename from the header, then makeup one like [tld].txt.gz
if not filename:
Expand Down