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

Download only a set of zone TLDs #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion config.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"icann.account.password": "Abcdef#12345678",
"authentication.base.url": "https://account-api.icann.org",
"czds.base.url": "https://czds-api.icann.org",
"working.directory": "/where/zonefiles/will/be/saved"
"working.directory": "/where/zonefiles/will/be/saved",
"tlds": []
}
11 changes: 8 additions & 3 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
password = config['icann.account.password']
authen_base_url = config['authentication.base.url']
czds_base_url = config['czds.base.url']
tlds = config.get('tlds', [])

# This is optional. Default to current directory
working_directory = config['working.directory']
Expand All @@ -49,7 +50,6 @@
working_directory = '.'



##############################################################################################################
# Second Step: authenticate the user to get an access_token.
# Note that the access_token is global for all the REST API calls afterwards
Expand All @@ -75,7 +75,7 @@ def get_zone_links(czds_base_url):

if status_code == 200:
zone_links = links_response.json()
print("{0}: The number of zone files to be downloaded is {1}".format(datetime.datetime.now(),len(zone_links)))
print("{0}: The number of zone files to be downloaded is {1}".format(datetime.datetime.now(),len(tlds) or len(zone_links)))
return zone_links
elif status_code == 401:
print("The access_token has been expired. Re-authenticate user {0}".format(username))
Expand Down Expand Up @@ -144,7 +144,12 @@ def download_zone_files(urls, working_directory):

# Download the zone files one by one
for link in urls:
download_one_zone(link, output_directory)
if len(tlds):
for tld in tlds:
if link.endswith('%s.zone' % tld):
download_one_zone(link, output_directory)
else:
download_one_zone(link, output_directory)

# Finally, download all zone files
start_time = datetime.datetime.now()
Expand Down