Created
September 22, 2013 17:43
-
-
Save gabrii/6662144 to your computer and use it in GitHub Desktop.
Checks github usernames availability of a list of usernames.
This file contains 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
from httplib2 import Http | |
# Exemple of usernames list (all combinations of 3 letters from a to z): | |
from string import letters | |
letters = letters[:26] | |
usernames = [ a+b+c for a in letters for b in letters for c in letters] | |
h = Http() | |
def available(username): | |
''' Return true if username is available, False if not, and raises error with unknown response code. ''' | |
resp, content = h.request("https://github.com/signup_check/username", "POST", 'value='+username) | |
if resp['status'] == '200': | |
return True | |
elif resp['status'] != '408': | |
raise Exception('Error '+resp['status']) | |
return False | |
def main(): | |
''' Print available usernames. ''' | |
for username in usernames: | |
if available(username): | |
print username | |
return 0 | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment