Last active
December 15, 2015 15:19
-
-
Save scheakur/5280844 to your computer and use it in GitHub Desktop.
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
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