Created
February 25, 2014 17:38
-
-
Save coppeliaMLA/9213856 to your computer and use it in GitHub Desktop.
Creates all 5 letter permutations of words, ranks them by how pronounceable they are, checks that they are a word in some language then checks whether the domain is free.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Created on Feb 6, 2014 | |
@author: sraper | |
''' | |
import itertools, urllib, urllib2, time, re, random | |
from bs4 import BeautifulSoup | |
def catchURL(queryURL): # Nicked this from someone. Afraid I can't remember who. Sorry | |
try: | |
queryResponse = urllib.urlopen(queryURL) | |
except urllib2.HTTPError, E: | |
if E.code in [400, 420]: | |
print("400 or 420") | |
time.sleep(600) | |
elif E.code == 503: | |
print("503") | |
time.sleep(60) | |
else: | |
print("Wait 3 mins") | |
time.sleep(180) | |
queryResponse = urllib.urlopen(queryURL) | |
return queryResponse | |
# Function to score name | |
def scoreName(name): | |
score = 0 | |
#Vowel consonant map | |
vcMap = [0, 0, 0, 0, 0] | |
vowels = ['a', 'e', 'i', 'o', 'u'] | |
conBlend = ['bl', 'br', 'pr', 'dr', 'fl', 'cl', 'gl', 'sl', 'cr', 'pl', 'fr', 'gr', 'tr', 'sc', 'sk', 'st', 'sw', 'sn', 'sm', 'wh', 'sh', 'th', 'tw', 'wr'] | |
for j in range(5): | |
if name[j] in vowels: | |
vcMap[j] = 1 | |
vowelCount = sum(vcMap)*3 | |
if vowelCount < 7: | |
score = score + vowelCount | |
#Double consonant at beginning and end | |
if (sum(vcMap[0:1]) == 0 and ''.join(name[0:1]) not in conBlend) or (sum(vcMap[3:4]) == 0 and ''.join(name[3:4]) not in conBlend): | |
score = score-10 | |
#Triple consontant anywhere | |
if sum(vcMap[0:2]) == 0 or sum(vcMap[1:3]) or sum(vcMap[2:4]) == 0: | |
score = score-10 | |
score=score + random.random() | |
#Letters I like | |
#=========================================================================== | |
# goodLetters = set(['z', 'q', 'u', 'o', 'x']) | |
# nameSet=set(name) | |
# goodLetterCount=len(goodLetters & nameSet) | |
# | |
# score = score + goodLetterCount | |
#=========================================================================== | |
return score | |
perm=list(itertools.permutations(list(map(chr, range(97, 123))),5)) | |
random.shuffle(perm) | |
#Score the permutations | |
scores = [] | |
for i in perm: | |
scores.append(scoreName(i)) | |
scores, perm = zip(*sorted(zip(scores, perm), reverse=True)) | |
file = open('/Users/sraper/workfile.txt', 'w') | |
for i in perm[0:500]: | |
#Check its a word | |
possible= ''.join(i) | |
print(possible) | |
d=catchURL('https://en.wiktionary.org/w/index.php?title=Special%3ASearch&profile=default&search=' + possible + '&fulltext=Search') | |
dSoup = BeautifulSoup(d) | |
if dSoup.body.findAll(text=re.compile('There were no results matching the query'), limit=1)==[]: | |
print('It is a word') | |
#Check domain is free | |
f=catchURL('http://www.checkdomain.com/cgi-bin/checkdomain.pl?domain='+possible) | |
soup = BeautifulSoup(f) | |
if soup.body.findAll(text=re.compile('already been registered'), limit=1)==[]: | |
print ('and it is free') | |
file.write(possible+'\n') | |
file.close() | |
print "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment