Skip to content

Instantly share code, notes, and snippets.

@gabrii
Created September 22, 2013 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrii/6662144 to your computer and use it in GitHub Desktop.
Save gabrii/6662144 to your computer and use it in GitHub Desktop.
Checks github usernames availability of a list of usernames.
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