Skip to content

Instantly share code, notes, and snippets.

@soulshake
Last active July 28, 2020 12:39
Show Gist options
  • Save soulshake/3cfacbf0694dc2c341c6 to your computer and use it in GitHub Desktop.
Save soulshake/3cfacbf0694dc2c341c6 to your computer and use it in GitHub Desktop.
A script to list registration prices of all Gandi TLDs at E rates
#!/usr/bin/env python
"""
Author: AJ Bowen
Created: 2014-10-09
A script to list registration prices of all Gandi TLDs at E rates
Prices correspond to a one-year registration except where a TLD requires a minimum registration
of more than one year.
Output is CSV format containing three fields:
1. TLD
2. Price
3. Minimum registration duration
"""
from __future__ import print_function
import xmlrpclib
import time
import csv
def tld_get_price(tld):
"""Return the price of a one-year registration of a TLD during the GoLive phase at E rates."""
catalog_spec = {
'product' : {
'description': "." + tld,
'type':'domain'
},
'action': {
'name':'create',
'param': {'tld_phase': 'golive'},
}
}
catalog = api.catalog.list(k, catalog_spec, 'USD', 'E')
price = catalog[0]['unit_price'][0]['price']
min_duration = catalog[0]['unit_price'][0]['min_duration']
return price, min_duration
# Enter your Gandi API key below, available at https://www.gandi.net/admin/api_key
k = ''
if k == '':
print("Please fill in your API key. Exiting.")
exit()
api = xmlrpclib.ServerProxy('https://rpc.gandi.net/xmlrpc/')
# Get a list of all TLDs offered by Gandi
tld_list = api.domain.tld.list(k)
print("Looking up registration prices for all {num} TLDs offered by Gandi.net \o/".format(num=len(tld_list)))
# Create a file for the output and write some column headings
f = open('gandi-rates.csv','w')
writer = csv.writer(f)
writer.writerow(['tld', 'registration price', 'minimum registration duration'])
# Loop through list of TLDs and get the price and minimum duration of each
# We'll wait a bit between calls to limit ourselves to about 10 calls a second
for tld_dict in tld_list:
tld_name = tld_dict['name']
tld_price, min_duration = tld_get_price(tld_name)
row = [ tld_name, tld_price, min_duration ]
writer.writerow(row)
print(tld_name, tld_price, min_duration, sep=', ')
time.sleep(0.1)
@Jan02
Copy link

Jan02 commented Jul 19, 2018

Hi,

are the dependencies included with python ? To list for A and different currency, I just change line 35 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment