Skip to content

Instantly share code, notes, and snippets.

@scheakur
Last active December 15, 2015 15:19
Show Gist options
  • Save scheakur/5280844 to your computer and use it in GitHub Desktop.
Save scheakur/5280844 to your computer and use it in GitHub Desktop.
def search(String fmt) {
def alpha = ('a'..'z').join('')
def num = ('0'..'9').join('')
def alphanum = alpha + num
def all = alphanum + '_'
def checkList = fmt.collect {
switch (it) {
case 'A': return alpha
case 'N': return num
case '.': return alphanum
case '+': return all
default: return it
}
}
checkAll('', checkList as List)
}
def checkAll(String id, List<String> checkList) {
if (checkList?.size() > 0) {
checkList[0].each {
checkAll(id + it, (checkList.size() > 1) ? checkList[1..-1] : null)
}
} else {
check(id)
}
}
def check(String id) {
try {
Thread.sleep(1000)
if (valid(id)) {
println id
}
} catch (Exception e) {
try {
Thread.sleep(3000)
if (valid(id)) {
println id
}
} catch (Exception e2) {
println 'E:' + id
}
}
}
def valid(String id) {
def url = "https://twitter.com/users/username_available?username=${id}"
def res = new URL(url).text
return res.contains('"valid":true')
}
search(args[0] as String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment