Created
September 14, 2011 03:24
-
-
Save Radagaisus/1215788 to your computer and use it in GitHub Desktop.
Check domains from a list of words using Domai.nr API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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