Permalink
Browse files

Add domainr package in addition to script

  • Loading branch information...
1 parent d74cdd2 commit bc50ad3225508852d28b7aab75bb0eccbc5061fe @zachwill committed Jan 21, 2012
Showing with 63 additions and 59 deletions.
  1. +2 −59 dom
  2. +58 −0 domainr/__init__.py
  3. +3 −0 setup.py
View
61 dom
@@ -1,64 +1,7 @@
#!/usr/bin/env python
-"""
-An easy way to see domain name availability from the command line.
-"""
-
-import json
-from argparse import ArgumentParser
-import requests
-from termcolor import colored
-
-
-def environment():
- """Parse any command line arguments."""
- parser = ArgumentParser()
- parser.add_argument('query', type=str, nargs='+',
- help="Your domain name query.")
- parser.add_argument('-i', '--info', action='store_true',
- help="Get information for a domain name.")
- args = parser.parse_args()
- return args
-
-
-def domainr(environment):
- """Use domainr to get information about domain names."""
- if environment.info:
- url = "http://domai.nr/api/json/info"
- else:
- url = "http://domai.nr/api/json/search"
- query = " ".join(environment.query)
- json_data = requests.get(url, params={'q': query})
- data = parse(json_data.content, environment.info)
- return data
-
-
-def parse(content, info):
- """Parse the relevant data from JSON."""
- data = json.loads(content)
- if not info:
- # Then we're dealing with a domain name search.
- output = []
- results = data['results']
- for domain in results:
- name = domain['domain']
- availability = domain['availability']
- if availability == 'available':
- name = colored(name, 'blue', attrs=['bold'])
- symbol = colored(u"\u2713", 'green')
- else:
- symbol = colored(u"\u2717", 'red')
- string = "%s %s" % (symbol, name)
- output.append(string)
- return '\n'.join(output)
- # Then the user wants information on a domain name.
- return data
-
-
-def main():
- args = environment()
- print domainr(args)
+from domainr import Domain
if __name__ == '__main__':
- main()
+ Domain().main()
View
@@ -0,0 +1,58 @@
+"""
+An easy way to see domain name availability from the command line.
+"""
+
+import json
+from argparse import ArgumentParser
+import requests
+from termcolor import colored
+
+
+class Domain(object):
+ """Main class for interacting with the domains API."""
+
+ def environment(self):
+ """Parse any command line arguments."""
+ parser = ArgumentParser()
+ parser.add_argument('query', type=str, nargs='+',
+ help="Your domain name query.")
+ parser.add_argument('-i', '--info', action='store_true',
+ help="Get information for a domain name.")
+ args = parser.parse_args()
+ return args
+
+ def search(self, environment):
+ """Use domainr to get information about domain names."""
+ if environment.info:
+ url = "http://domai.nr/api/json/info"
+ else:
+ url = "http://domai.nr/api/json/search"
+ query = " ".join(environment.query)
+ json_data = requests.get(url, params={'q': query})
+ data = self.parse(json_data.content, environment.info)
+ return data
+
+ def parse(self, content, info):
+ """Parse the relevant data from JSON."""
+ data = json.loads(content)
+ if not info:
+ # Then we're dealing with a domain name search.
+ output = []
+ results = data['results']
+ for domain in results:
+ name = domain['domain']
+ availability = domain['availability']
+ if availability == 'available':
+ name = colored(name, 'blue', attrs=['bold'])
+ symbol = colored(u"\u2713", 'green')
+ else:
+ symbol = colored(u"\u2717", 'red')
+ string = "%s %s" % (symbol, name)
+ output.append(string)
+ return '\n'.join(output)
+ # Then the user wants information on a domain name.
+ return data
+
+ def main(self):
+ args = self.environment()
+ print self.search(args)
View
@@ -10,6 +10,9 @@
author_email="hey@zachwill.com",
url="http://github.com/zachwill/dom",
license="MIT",
+ packages=[
+ "domainr"
+ ],
scripts=[
"dom"
],

0 comments on commit bc50ad3

Please sign in to comment.