Skip to content

Instantly share code, notes, and snippets.

@elpaso
Created March 18, 2019 14:11
Show Gist options
  • Save elpaso/eecc0b4e780e7ffc7dc8739d39dd1312 to your computer and use it in GitHub Desktop.
Save elpaso/eecc0b4e780e7ffc7dc8739d39dd1312 to your computer and use it in GitHub Desktop.
name matic
#!/usr/bin/env python3
# Usage: cat nameslist.txt | ./namematic.py
import fileinput
import urllib3
import urllib.request
def url_is_alive(url):
"""
Checks that a given URL is reachable.
:param url: A URL
:rtype: bool
"""
request = urllib.request.Request(url)
request.get_method = lambda: 'HEAD'
try:
urllib.request.urlopen(request, timeout=4)
return True
except:
return False
def _check_sites(name):
for tld in ('com', 'net', 'eu'):
domain = "http://www.%s.%s" % (name.lower(), tld)
if url_is_alive(domain):
return domain
return False
words = []
for line in fileinput.input():
words.append(line.strip())
words.sort()
for w in words:
if not w:
continue
if w.startswith('-') or w.startswith('#'):
continue
if w.startswith('+'):
w = w[1:]
print("-" * 80)
print("%s" % w.capitalize())
print("-" * 80)
for w2 in words:
if w == w2 or not w2 or w2.startswith('+') or w2.startswith('#'):
continue
if w2.startswith('-'):
w2 = w2[1:]
name = "%s%s" % (w.capitalize(), w2.capitalize())
registered = _check_sites(name)
if registered:
print("%s -> registered: %s" % (name, registered))
else:
print(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment