Skip to content

Instantly share code, notes, and snippets.

@Radagaisus
Created September 14, 2011 03:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Radagaisus/1215788 to your computer and use it in GitHub Desktop.
Save Radagaisus/1215788 to your computer and use it in GitHub Desktop.
Check domains from a list of words using Domai.nr API
#!/usr/bin/env python
# encoding: utf-8
"""
Check all available urls from the word list.
urls that aren't the exact word aren't considered.
"""
import urllib
import json
import re
import time
def main():
# Clean the file
with open('domains.txt','w') as reset_file:
pass
# Open the list and start iterating
with open('words.txt', 'r') as words:
for word in words:
word = word.rstrip()
print "Testing availability: " + word
# Get a new word from the list
url = 'http://domai.nr/api/json/search?q=' + word
# Call Domainr
print "Sent request to domainr..."
data = urllib.urlopen(url)
# Convert JSON
print "Response Received..."
print "Parsing results..."
domains = json.loads(data.read())
# Parse results
found = False
for domain in domains.get("results"):
if domain.get("availability") == "available":
if re.sub('\.','', domain.get("domain")) == word or re.search('([\w\.]+)(?=\.\w+)', domain.get("domain")).group(0) == word:
found = True
# Save to file
with open('domains.txt', 'a') as f:
f.write(domain.get("domain") + "\n")
# Report to stdout
print "Available: " + word + " - " + domain.get("domain")
if not found:
print "No domain is available."
print "Going to sleep.\n---------------------\n"
# Don't make domai.nr cringe, go to sleep
time.sleep(5)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment