From f9bc7176dcf356d6f1221e9c467b2363b65faf5a Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Fri, 21 Sep 2012 05:31:39 +0200 Subject: [PATCH] Updated grammar, including update date recognition --- pythonwhois/__init__.py | 16 ++++++++++++++-- test.py | 11 ++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/pythonwhois/__init__.py b/pythonwhois/__init__.py index a9b5165..582c3a3 100644 --- a/pythonwhois/__init__.py +++ b/pythonwhois/__init__.py @@ -29,9 +29,17 @@ grammar = { 'Record will expire on\s?[.]*:\s?(?P.+)', 'Domain expires\s?[.]*:\s*?(?P.+)', 'Record expires on\s?[.]*:?\s*?(?P.+)'], + 'updated_date': ['Database last updated on\s?[.]*:?\s*?(?P.+)\s[a-z]+\.?', + 'Record last updated on\s?[.]*:\s?(?P.+)\.', + 'Domain record last updated\s?[.]*:\s*?(?P.+)', + 'Domain Last Updated\s?[.]*:\s*?(?P.+)', + 'Last updated on:\s?(?P.+)', + 'Date Modified\s?[.]*:\s?(?P.+)', + 'Last update of whois database:\s?[a-z]{3}, (?P.+) [a-z]{3}'], 'registrar': ['Registered through:\s?(?P.+)', 'Registrar Name:\s?(?P.+)', - 'Record maintained by:\s?(?P.+)'], + 'Record maintained by:\s?(?P.+)', + 'Registration Service Provided By:\s?(?P.+)'], 'whois_server': ['Registrar Whois:\s?(?P.+)'], 'name_servers': ['(?Pd?ns[0-9]+\.([a-z0-9-]+\.)+[a-z0-9]+)', '(?P[a-z0-9-]+\.d?ns[0-9]*\.([a-z0-9-]+\.)+[a-z0-9]+)', @@ -76,7 +84,8 @@ grammar = { 'creation_date': 'created:\s*(?P.+)', 'expiration_date': 'paid-till:\s*(?P.+)', 'name_servers': 'nserver:\s*(?P.+)', - 'status': 'state:\s*(?P.+)' + 'status': 'state:\s*(?P.+)', + 'updated_date': 'Last updated on (?P.+) [a-z]{3}' } } @@ -133,6 +142,9 @@ def whois(domain): if data['creation_date'] is not None: data['creation_date'] = parse_dates(data['creation_date']) + if data['updated_date'] is not None: + data['updated_date'] = parse_dates(data['updated_date']) + if data['name_servers'] is not None: data['name_servers'] = remove_duplicates(data['name_servers']) diff --git a/test.py b/test.py index 8e1035a..1d96a0a 100644 --- a/test.py +++ b/test.py @@ -1,8 +1,17 @@ #!/usr/bin/python import sys, pythonwhois -result = pythonwhois.whois(sys.argv[1]) +testlist = open("testlist.txt").readlines() + +#for line in testlist: +# result = pythonwhois.whois(line) +# +# if result['updated_date'] is None: +# print "WHOIS for %s does not contain an update date?" % line + +result = pythonwhois.whois("google.com") print result + #print "Creation date: ", #print result['creation_date'] #print "Expiration date: ",