Skip to content

Instantly share code, notes, and snippets.

@adamghill
Last active December 31, 2015 00:09
Show Gist options
  • Save adamghill/7905158 to your computer and use it in GitHub Desktop.
Save adamghill/7905158 to your computer and use it in GitHub Desktop.
Validate that an .io TLD is available to purchase. Uses https://gist.github.com/isaacbw/6831088#file-available-txt as the initial seed of domains to check. Props to http://whomsy.com/ for not blocking me.
import requests
gist_url = 'https://gist.github.com/isaacbw/6831088/raw/33b0072c6160f0fe304e998fa04715117456414d/available.txt'
gist_response = requests.get(gist_url)
if gist_response.ok:
with open('available.txt', 'w') as file:
lines = gist_response.content.split('\n')
available_count = 0
for idx, line in enumerate(lines):
if idx % 10 == 0:
print(idx)
whomsy_url = 'http://whomsy.com/api/{domain}'.format(**{
'domain': line,
})
whomsy_response = requests.get(whomsy_url)
if whomsy_response.ok:
whomsy_json = whomsy_response.json()
message = whomsy_json.get('message')
if message and 'is available for purchase' in message:
# print(whomsy_json)
available_count = available_count + 1
domain = whomsy_json.get('domain')
file.write('{domain}\n'.format(**{'domain': domain}))
print('Found {available_count} available domains.'.format(**{'available_count': available_count}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment