diff --git a/config.sample.json b/config.sample.json index 87f746c..454abdf 100644 --- a/config.sample.json +++ b/config.sample.json @@ -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": [] } diff --git a/download.py b/download.py index ce1268b..7b200eb 100644 --- a/download.py +++ b/download.py @@ -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'] @@ -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 @@ -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)) @@ -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()