Skip to content

Instantly share code, notes, and snippets.

@crock
Last active July 7, 2018 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crock/1db75c9b1be159b1c8d2c1020322d895 to your computer and use it in GitHub Desktop.
Save crock/1db75c9b1be159b1c8d2c1020322d895 to your computer and use it in GitHub Desktop.
import re
class Filters(object):
config = {}
def __init__(self, obj):
self.config = obj
def is_select_tld(self, domain):
for tld in self.config['tlds']:
pattern = '(?:[a-zA-Z0-9-]+\.)%s' % tld
match = re.match(pattern, domain)
if match is not None:
return True
return False
def is_proper_length(self, domain, include_tld=False):
if include_tld is True:
if len(domain) <= self.config['maxDomainLength']:
return True
else:
return False
else:
name = domain.split('.')[0]
if len(name) <= self.config['maxDomainLength']:
return True
else:
return False
def number_of_characters(self, domain, include_tld=False):
if include_tld is True:
return len(domain)
else:
name = domain.split('.')[0]
return len(name)
def contains_keyword(self, domain):
tld = domain.split('.')[1]
for keyword in self.config['keywords']:
pattern = '(?:[a-zA-Z0-9-]+)?%s(?:[a-zA-Z0-9-]+)?(?:\.%s)$' % (keyword, tld)
match = re.match(pattern, domain)
if match is not None:
return True
return False
import os.path
import json
import requests
import arrow
import progressbar
from lib.Filters import Filters
local = arrow.now("America/New_York")
tomorrow = local.shift(days=1).format("M-DD-YYYY")
url = "http://www.namejet.com/download/%s.txt" % tomorrow
# csv = "https://snapnames.com/search_dl.sn?type=12"
filename = tomorrow + ".txt"
fp = open("config.json", "r")
config = json.load(fp)
fp.close()
def download_file(url, filename):
response = requests.get(url, stream=True)
if response.status_code is 200:
if not os.path.exists("tmp"):
os.makedirs("tmp")
fx = open(os.path.join('tmp', filename), 'wb')
file_size = int(response.headers['Content-Length'])
chunk = 1
num_bars = file_size / chunk
bar = progressbar.ProgressBar(maxval=num_bars).start()
i = 0
for chunk in response.iter_content():
fx.write(chunk)
bar.update(i)
i += 1
fx.close()
print("Done.")
else:
print("Couldn\'t get file.")
def filter_domains(domains):
for domain in domains:
filter = Filters(config)
a = filter.is_select_tld(domain)
b = filter.is_proper_length(domain)
c = filter.contains_keyword(domain)
if not os.path.exists("results"):
os.makedirs("results")
fx = open(os.path.join('results', 'results_%s' % filename), 'a')
if a is True and b is True and c is True:
print(domain)
fx.write(domain + '\n')
fx.close()
def main():
if os.path.isfile(os.path.join('tmp', filename)):
pass
else:
print("Downloading tomorrow\'s list of expiring domains...")
download_file(url, filename)
print("Filtering domains according to your specified conditions...")
domains = [line.rstrip('\n') for line in open(os.path.join('tmp', filename))]
filter_domains(domains)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment