Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find every available domain from a dictionary
#!/usr/bin/env python
# encoding: utf-8
import sys, json, urllib
from optparse import OptionParser
def main():
parser = OptionParser()
parser.add_option("-e", "--extension", action="append", type="string", dest="extensions", help="specify domain extension", default=[])
parser.add_option("-a", "--availability", action="store", type="choice", choices=["taken", "maybe", "available", "unavailable", "tld"], dest="availability", help="specifiy level of availability", default="available")
parser.set_defaults(verbose=True)
(options, args) = parser.parse_args()
for line in sys.stdin:
domain = line.strip()
response = json.load(urllib.urlopen("http://domai.nr/api/json/search?q=%s" % domain))
for result in response['results']:
if result['availability'] in [options.availability]:
if options.extensions:
for ext in options.extensions:
if result["domain"].endswith(ext):
print result['domain']
else:
print result['domain']
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, SystemExit):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment